nsString::Compare(...) broken.

VERIFIED FIXED

Status

()

Core
HTML: Parser
P2
major
VERIFIED FIXED
19 years ago
17 years ago

People

(Reporter: jst, Assigned: rickg)

Tracking

Trunk
All
Windows NT
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

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

Updated

19 years ago
Status: NEW → ASSIGNED
(Assignee)

Comment 1

19 years ago
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
Last Resolved: 19 years ago
Resolution: --- → FIXED

Comment 2

19 years ago
qa contact set to reporter for verify
QA Contact: 4122

Comment 3

17 years ago
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.