Closed Bug 413488 Opened 17 years ago Closed 16 years ago

nsACString::Find in nsStringAPI is buggy!

Categories

(Core :: XPCOM, defect, P1)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9beta4

People

(Reporter: prasad, Assigned: prasad)

Details

Attachments

(2 files)

Code from:
  http://lxr.mozilla.org/mozilla/source/xpcom/glue/nsStringAPI.cpp#710

710 nsACString::Find(const self_type& aStr, PRUint32 aOffset,
711                  ComparatorFunc c) const
712 {
713   const char_type *begin;
714   PRUint32 len = aStr.BeginReading(&begin);
715 
716   if (aOffset > len)
717     return -1;
718 
719   PRInt32 found = Find(begin + aOffset, len - aOffset, c);
720   if (found == -1)
721     return found;
722 
723   return found + aOffset;
724 }

The Find function above is supposed to find aStr starting at aOffset on this string.  But the code above seems to something completely wrong!

The other function Find being called inside this actually finds a "char *" of a given length in this string.

The attached patch fixes it and also makes minor (and silly) changes in a couple of other places.
Attachment #298460 - Flags: review?(benjamin)
Summary: nsACString::Find(const self_type& aStr ... code is buggy! → nsACString::Find in nsStringAPI is buggy!
Comment on attachment 298460 [details] [diff] [review]
Fixes nsACString::Find function

This is ok, but it must have a unit test before landing.
Attachment #298460 - Flags: review?(benjamin) → review+
I think this should block beta4, as a serious error in the frozen string API.
Flags: blocking1.9?
Priority: -- → P1
Did this regress or is this old?
Flags: blocking1.9? → blocking1.9+
This is a mismatch between the new frozen string API and the old nonfrozen one, so it's effectively a regression for extension authors.
Keywords: checkin-needed
As per comment #1, this needs a unit test before it can land.
Flags: in-testsuite?
Keywords: checkin-needed
This patch adds test cases for the Find function in nsStringAPI.  Apart from being a test case for this bug, it has test cases to test few other use cases of the Find functions too.
Attachment #302256 - Flags: review?(benjamin)
Attachment #302256 - Flags: review?(benjamin) → review+
Keywords: checkin-needed
Checking in xpcom/glue/nsStringAPI.cpp;
/cvsroot/mozilla/xpcom/glue/nsStringAPI.cpp,v  <--  nsStringAPI.cpp
new revision: 3.11; previous revision: 3.10
done
Checking in xpcom/tests/TestStringAPI.cpp;
/cvsroot/mozilla/xpcom/tests/TestStringAPI.cpp,v  <--  TestStringAPI.cpp
new revision: 1.3; previous revision: 1.2
done
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9beta4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: