nsString2::Equals(nsString& and nsStr&, ...) bug...

VERIFIED FIXED

Status

()

P3
critical
VERIFIED FIXED
19 years ago
19 years ago

People

(Reporter: jst, Assigned: rickg)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

19 years ago
(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;
(Assignee)

Updated

19 years ago
Status: NEW → ASSIGNED
(Assignee)

Comment 1

19 years ago
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.
(Reporter)

Comment 2

19 years ago
Oops! Worked in my tests, guess I didn't heve very good tests...
(Assignee)

Updated

19 years ago
Status: ASSIGNED → NEW
(Assignee)

Updated

19 years ago
Status: NEW → RESOLVED
Last Resolved: 19 years ago
Resolution: --- → FIXED
(Assignee)

Comment 3

19 years ago
The fix has been checked in.
(Assignee)

Comment 4

19 years ago
The fix has been checked in.

Updated

19 years ago
Status: RESOLVED → VERIFIED

Comment 5

19 years ago
Marking Verified Fixed per rickg's input.
You need to log in before you can comment on or make changes to this bug.