From 6e4e20009b00dc7482c9220bddbbc90375ddc24a Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Sun, 14 Nov 1999 06:22:52 +0000 Subject: [PATCH] bug18337 and fixes for embedded nulls; r=harishd git-svn-id: svn://10.0.0.236/trunk@53450 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsStr.cpp | 30 ++++++--- mozilla/string/obsolete/nsStr.h | 29 ++++++--- mozilla/string/obsolete/nsString.cpp | 68 +++++++++----------- mozilla/string/obsolete/nsString.h | 5 +- mozilla/string/obsolete/nsString2.cpp | 70 ++++++++++++--------- mozilla/string/obsolete/nsString2.h | 9 +-- mozilla/xpcom/ds/bufferRoutines.h | 53 ++++++++-------- mozilla/xpcom/ds/nsCRT.cpp | 63 ++++++++++--------- mozilla/xpcom/ds/nsStr.cpp | 30 ++++++--- mozilla/xpcom/ds/nsStr.h | 29 ++++++--- mozilla/xpcom/ds/nsString.cpp | 68 +++++++++----------- mozilla/xpcom/ds/nsString.h | 5 +- mozilla/xpcom/ds/nsString2.cpp | 70 ++++++++++++--------- mozilla/xpcom/ds/nsString2.h | 9 +-- mozilla/xpcom/string/obsolete/nsStr.cpp | 30 ++++++--- mozilla/xpcom/string/obsolete/nsStr.h | 29 ++++++--- mozilla/xpcom/string/obsolete/nsString.cpp | 68 +++++++++----------- mozilla/xpcom/string/obsolete/nsString.h | 5 +- mozilla/xpcom/string/obsolete/nsString2.cpp | 70 ++++++++++++--------- mozilla/xpcom/string/obsolete/nsString2.h | 9 +-- 20 files changed, 420 insertions(+), 329 deletions(-) diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index 211105c4724..dc1a0379c37 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -43,6 +43,7 @@ //static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1."; static const PRUnichar gCommonEmptyBuffer[1] = {0}; +static nsresult gStringAcquiredMemory = NS_OK; /** * This method initializes all the members of the nsStr structure @@ -303,10 +304,15 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) { } /** - * - * @update gess1/7/99 - * @param - * @return + * This method removes characters from the given set from this string. + * NOTE: aSet is a char*, and it's length is computed using strlen, which assumes null termination. + * + * @update gess 11/7/99 + * @param aDest + * @param aSet + * @param aEliminateLeading + * @param aEliminateTrailing + * @return nothing */ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ @@ -622,12 +628,12 @@ PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { PRUint32 theSize=(theNewCapacity<s2 */ -PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2) -{ +PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2) { if(s1 && s2) { for (;;) { PRUnichar c1 = *s1++; @@ -259,12 +260,13 @@ PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2) /** * Compare unichar string ptrs, stopping at the 1st null or nth char. * NOTE: If either is null, we return 0. - * @update gess7/30/98 + * NOTE: We DO NOT terminate the search upon encountering NULL's before N + * + * @update gess 11/10/99 * @param s1 and s2 both point to unichar strings * @return 0 if they match, -1 if s1s2 */ -PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) -{ +PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) { if(s1 && s2) { if(n != 0) { do { @@ -274,23 +276,22 @@ PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) if (c1 < c2) return -1; return 1; } - if ((0==c1) || (0==c2)) break; } while (--n != 0); } } return 0; } - /** * Compare unichar string ptrs without regard to case * NOTE: If both are null, we return 0. - * @update gess7/30/98 + * NOTE: We terminate the search upon encountering NULL + * + * @update gess 11/10/99 * @param s1 and s2 both point to unichar strings * @return 0 if they match, -1 if s1s2 */ -PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2) -{ +PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2) { if(s1 && s2) { for (;;) { PRUnichar c1 = *s1++; @@ -313,12 +314,13 @@ PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2) * Compare unichar string ptrs, stopping at the 1st null or nth char; * also ignoring the case of characters. * NOTE: If both are null, we return 0. - * @update gess7/30/98 + * NOTE: We DO NOT terminate the search upon encountering NULL's before N + * + * @update gess 11/10/99 * @param s1 and s2 both point to unichar strings * @return 0 if they match, -1 if s1s2 */ -PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) -{ +PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) { if(s1 && s2) { if(n != 0){ do { @@ -332,7 +334,6 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) return 1; } } - if ((0==c1) || (0==c2)) break; } while (--n != 0); } } @@ -343,13 +344,14 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRUint32 n) /** * Compare a unichar string ptr to cstring. * NOTE: If both are null, we return 0. + * NOTE: We terminate the search upon encountering NULL's + * * @update gess7/30/98 * @param s1 points to unichar string * @param s2 points to cstring * @return 0 if they match, -1 if s1s2 */ -PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2) -{ +PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2) { if(s1 && s2) { for (;;) { PRUnichar c1 = *s1++; @@ -368,15 +370,16 @@ PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2) /** * Compare a unichar string ptr to cstring, up to N chars. * NOTE: If both are null, we return 0. - * @update gess7/30/98 + * NOTE: We DO NOT terminate the search upon encountering NULL's before N + * + * @update gess 11/10/99 * @param s1 points to unichar string * @param s2 points to cstring * @return 0 if they match, -1 if s1s2 */ -PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRUint32 n) -{ +PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRUint32 n) { if(s1 && s2) { - if(n != 0){ + if(0s2 */ -PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2) -{ +PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2) { if(s1 && s2) { for (;;) { PRUnichar c1 = *s1++; @@ -422,13 +426,14 @@ PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2) /** * Caseless compare up to N chars between unichar string ptr to cstring. * NOTE: If both are null, we return 0. - * @update gess7/30/98 + * NOTE: We DO NOT terminate the search upon encountering NULL's before N + * + * @update gess 11/10/99 * @param s1 points to unichar string * @param s2 points to cstring * @return 0 if they match, -1 if s1s2 */ -PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n) -{ +PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n) { if(s1 && s2){ if(n != 0){ do { @@ -442,13 +447,13 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRUint32 n) return 1; } } - if (c1 == 0) break; } while (--n != 0); } } return 0; } + PRUnichar* nsCRT::strdup(const PRUnichar* str) { PRUint32 len = nsCRT::strlen(str) + 1; // add one for null diff --git a/mozilla/xpcom/ds/nsStr.cpp b/mozilla/xpcom/ds/nsStr.cpp index 211105c4724..dc1a0379c37 100644 --- a/mozilla/xpcom/ds/nsStr.cpp +++ b/mozilla/xpcom/ds/nsStr.cpp @@ -43,6 +43,7 @@ //static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1."; static const PRUnichar gCommonEmptyBuffer[1] = {0}; +static nsresult gStringAcquiredMemory = NS_OK; /** * This method initializes all the members of the nsStr structure @@ -303,10 +304,15 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) { } /** - * - * @update gess1/7/99 - * @param - * @return + * This method removes characters from the given set from this string. + * NOTE: aSet is a char*, and it's length is computed using strlen, which assumes null termination. + * + * @update gess 11/7/99 + * @param aDest + * @param aSet + * @param aEliminateLeading + * @param aEliminateTrailing + * @return nothing */ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ @@ -622,12 +628,12 @@ PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { PRUint32 theSize=(theNewCapacity<