Closed
Bug 9279
Opened 25 years ago
Closed 25 years ago
nsString2::Equals(nsString& and nsStr&, ...) bug...
Categories
(Core :: XPCOM, defect, P3)
Core
XPCOM
Tracking
()
VERIFIED
FIXED
People
(Reporter: jst, Assigned: rickg)
Details
(I'm assigning this to you rick since I saw that you fixed #9190, fixing that will introduce this one...) nsString2::Equals() calls Compare but it calls it with the length of the shorter string (MinLen()) as the length argument, this is wrong, Compare should be called with the length of the longer strings as the length argument... This patch fixes the problem and also makes nsString::Equals(nsIAtom...) use the aIgnoreCase argument... RCS file: /cvsroot/mozilla/xpcom/ds/nsString2.cpp,v retrieving revision 1.29 diff -u -r1.29 nsString2.cpp --- nsString2.cpp 1999/06/17 19:15:57 1.29 +++ nsString2.cpp 1999/07/05 12:51:09 @@ -1566,7 +1566,7 @@ * @return TRUE if equal */ PRBool nsString2::Equals(const nsString2& aString,PRBool aIgnoreCase) const { - PRInt32 result=nsStr::Compare(*this,aString,MinInt(mLength,aString.mLength),aIgnoreCase) ; + PRInt32 result=nsStr::Compare(*this,aString,MaxInt(mLength,aString.mLength),aIgnoreCase) ; return PRBool(0==result); } @@ -1578,7 +1578,7 @@ * @return TRUE if equal */ PRBool nsString2::Equals(const nsStr& aString,PRBool aIgnoreCase) const { - PRInt32 result=nsStr::Compare(*this,aString,MinInt(mLength,aString.mLength),aIgnoreCase) ; + PRInt32 result=nsStr::Compare(*this,aString,MaxInt(mLength,aString.mLength), aIgnoreCase); return PRBool(0==result); } @@ -1656,7 +1656,13 @@ NS_ASSERTION(0!=aAtom,kNullPointerError); PRBool result=PR_FALSE; if(aAtom){ - PRInt32 cmp=nsCRT::strcasecmp(mUStr,aAtom->GetUnicode()); + PRInt32 cmp; + + if (aIgnoreCase) + cmp=nsCRT::strcasecmp(mUStr,aAtom->GetUnicode()); + else + cmp=nsCRT::strcmp(mUStr,aAtom->GetUnicode()); + result=PRBool(0==cmp); } return result;
The error you cited was real, but the fix was incorrect. I will have a fix in the next update to the string class in a few days. Thanks.
Oops! Worked in my tests, guess I didn't heve very good tests...
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•