diff --git a/base/src/nsString.cpp b/base/src/nsString.cpp index 62a77a9a3782..c160e4da5edb 100644 --- a/base/src/nsString.cpp +++ b/base/src/nsString.cpp @@ -623,7 +623,13 @@ nsString& nsString::operator=(char aChar) { * @return this *------------------------------------------------------*/ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { - if(aStr!=0) { + if((0 == aLength) || (nsnull == aStr)) { + mLength=0; + if (nsnull != mStr) { + mStr[0]=0; + } + + } else { PRInt32 len=(kNotFound==aLength) ? nsCRT::strlen(aStr) : aLength; if(mCapacity< len ) EnsureCapacityFor(len); @@ -631,13 +637,7 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mLength=len; mStr[mLength]=0; } - else { - mLength=0; //This little bit of code handles the case - //where some blockhead hands us a null string - if (nsnull != mStr) { - mStr[0]=0; - } - } + return *this; } @@ -1512,8 +1512,20 @@ PRInt32 nsString::operator>=(const PRUnichar *s) const {return Compare(s)==0;} * @return TRUE if equal *------------------------------------------------------*/ PRBool nsString::Equals(const nsString& aString) const { - PRInt32 result=nsCRT::strcmp(mStr,aString.mStr); - return PRBool(0==result); + PRBool result; + + if (mLength != aString.mLength) { + result = PR_FALSE; + + } else if (0 == mLength) { + result = PR_TRUE; + + } else { + result = (0 == nsCRT::strcmp(mStr,aString.mStr)); + } + + + return result; } diff --git a/string/obsolete/nsString.cpp b/string/obsolete/nsString.cpp index 62a77a9a3782..c160e4da5edb 100644 --- a/string/obsolete/nsString.cpp +++ b/string/obsolete/nsString.cpp @@ -623,7 +623,13 @@ nsString& nsString::operator=(char aChar) { * @return this *------------------------------------------------------*/ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { - if(aStr!=0) { + if((0 == aLength) || (nsnull == aStr)) { + mLength=0; + if (nsnull != mStr) { + mStr[0]=0; + } + + } else { PRInt32 len=(kNotFound==aLength) ? nsCRT::strlen(aStr) : aLength; if(mCapacity< len ) EnsureCapacityFor(len); @@ -631,13 +637,7 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mLength=len; mStr[mLength]=0; } - else { - mLength=0; //This little bit of code handles the case - //where some blockhead hands us a null string - if (nsnull != mStr) { - mStr[0]=0; - } - } + return *this; } @@ -1512,8 +1512,20 @@ PRInt32 nsString::operator>=(const PRUnichar *s) const {return Compare(s)==0;} * @return TRUE if equal *------------------------------------------------------*/ PRBool nsString::Equals(const nsString& aString) const { - PRInt32 result=nsCRT::strcmp(mStr,aString.mStr); - return PRBool(0==result); + PRBool result; + + if (mLength != aString.mLength) { + result = PR_FALSE; + + } else if (0 == mLength) { + result = PR_TRUE; + + } else { + result = (0 == nsCRT::strcmp(mStr,aString.mStr)); + } + + + return result; } diff --git a/xpcom/ds/nsString.cpp b/xpcom/ds/nsString.cpp index 62a77a9a3782..c160e4da5edb 100644 --- a/xpcom/ds/nsString.cpp +++ b/xpcom/ds/nsString.cpp @@ -623,7 +623,13 @@ nsString& nsString::operator=(char aChar) { * @return this *------------------------------------------------------*/ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { - if(aStr!=0) { + if((0 == aLength) || (nsnull == aStr)) { + mLength=0; + if (nsnull != mStr) { + mStr[0]=0; + } + + } else { PRInt32 len=(kNotFound==aLength) ? nsCRT::strlen(aStr) : aLength; if(mCapacity< len ) EnsureCapacityFor(len); @@ -631,13 +637,7 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mLength=len; mStr[mLength]=0; } - else { - mLength=0; //This little bit of code handles the case - //where some blockhead hands us a null string - if (nsnull != mStr) { - mStr[0]=0; - } - } + return *this; } @@ -1512,8 +1512,20 @@ PRInt32 nsString::operator>=(const PRUnichar *s) const {return Compare(s)==0;} * @return TRUE if equal *------------------------------------------------------*/ PRBool nsString::Equals(const nsString& aString) const { - PRInt32 result=nsCRT::strcmp(mStr,aString.mStr); - return PRBool(0==result); + PRBool result; + + if (mLength != aString.mLength) { + result = PR_FALSE; + + } else if (0 == mLength) { + result = PR_TRUE; + + } else { + result = (0 == nsCRT::strcmp(mStr,aString.mStr)); + } + + + return result; } diff --git a/xpcom/string/obsolete/nsString.cpp b/xpcom/string/obsolete/nsString.cpp index 62a77a9a3782..c160e4da5edb 100644 --- a/xpcom/string/obsolete/nsString.cpp +++ b/xpcom/string/obsolete/nsString.cpp @@ -623,7 +623,13 @@ nsString& nsString::operator=(char aChar) { * @return this *------------------------------------------------------*/ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { - if(aStr!=0) { + if((0 == aLength) || (nsnull == aStr)) { + mLength=0; + if (nsnull != mStr) { + mStr[0]=0; + } + + } else { PRInt32 len=(kNotFound==aLength) ? nsCRT::strlen(aStr) : aLength; if(mCapacity< len ) EnsureCapacityFor(len); @@ -631,13 +637,7 @@ nsString& nsString::SetString(const PRUnichar* aStr,PRInt32 aLength) { mLength=len; mStr[mLength]=0; } - else { - mLength=0; //This little bit of code handles the case - //where some blockhead hands us a null string - if (nsnull != mStr) { - mStr[0]=0; - } - } + return *this; } @@ -1512,8 +1512,20 @@ PRInt32 nsString::operator>=(const PRUnichar *s) const {return Compare(s)==0;} * @return TRUE if equal *------------------------------------------------------*/ PRBool nsString::Equals(const nsString& aString) const { - PRInt32 result=nsCRT::strcmp(mStr,aString.mStr); - return PRBool(0==result); + PRBool result; + + if (mLength != aString.mLength) { + result = PR_FALSE; + + } else if (0 == mLength) { + result = PR_TRUE; + + } else { + result = (0 == nsCRT::strcmp(mStr,aString.mStr)); + } + + + return result; }