Closed Bug 1745 Opened 26 years ago Closed 26 years ago

nsString::Compare(...) broken.

Categories

(Core :: DOM: HTML Parser, defect, P2)

All
Windows NT
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: jst, Assigned: rickg)

Details

Ok, this is not a parser problem but I didn't see a more suitable component in
bugzilla. Anyhow...

nsString("foobar").Compare("foo");

returns 0, which is wrong, it doesn't check past the end of the shorter string
so that's why it doesn't work. Here's a patch that fixes this problem...

diff -c nglayout-latest/mozilla/base/src/nsString.cpp
vmproj/mozilla/base/src/nsString.cpp
*** nglayout-latest/mozilla/base/src/nsString.cpp	Wed Nov 25 13:11:56 1998
--- vmproj/mozilla/base/src/nsString.cpp	Fri Nov 27 18:49:05 1998
***************
*** 1534,1542 ****
        return 1;
      }
      if (aIgnoreCase) {
!       return nsCRT::strncasecmp(mStr,aCString,maxlen);
      }
!     return nsCRT::strncmp(mStr,aCString,maxlen);
    }

    if (aIgnoreCase) {
--- 1534,1542 ----
        return 1;
      }
      if (aIgnoreCase) {
!       return nsCRT::strncasecmp(mStr,aCString,maxlen + 1);
      }
!     return nsCRT::strncmp(mStr,aCString,maxlen + 1);
    }

    if (aIgnoreCase) {
***************
*** 1561,1569 ****
      return 1;
    }
    if (aIgnoreCase) {
!     return nsCRT::strncasecmp(mStr,S.mStr,maxlen);
    }
!   return nsCRT::strncmp(mStr,S.mStr,maxlen);
  }

  /**
--- 1561,1569 ----
      return 1;
    }
    if (aIgnoreCase) {
!     return nsCRT::strncasecmp(mStr,S.mStr,maxlen + 1);
    }
!   return nsCRT::strncmp(mStr,S.mStr,maxlen + 1);
  }

  /**
***************
*** 1588,1596 ****
        return 1;
      }
      if (aIgnoreCase) {
!       return nsCRT::strncasecmp(mStr,aString,maxlen);
      }
!     return nsCRT::strncmp(mStr,aString,maxlen);
    }

    if (aIgnoreCase) {
--- 1588,1596 ----
        return 1;
      }
      if (aIgnoreCase) {
!       return nsCRT::strncasecmp(mStr,aString,maxlen + 1);
      }
!     return nsCRT::strncmp(mStr,aString,maxlen + 1);
    }

    if (aIgnoreCase) {
Status: NEW → ASSIGNED
The problem was that we were calling strncmp rather than strcmp, with a length
specified as the longest string in comparision. This caused a match since we
only compared exactly n chars.
Status: ASSIGNED → RESOLVED
Closed: 26 years ago
Resolution: --- → FIXED
qa contact set to reporter for verify
QA Contact: 4122
http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsStr.cpp#599
PRInt32 nsStr::StrCompare(const nsStr& aDest,const nsStr& aSource,PRInt32
aCount,PRBool aIgnoreCase) {
//Since the caller didn't give us a length to test, and minlen characters matched,
//we have to assume that the longer string is greater.

is the closest thing i can find to this stuff, it's totally different, but it is
designed to consider this issue.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.