Closed Bug 108734 Opened 23 years ago Closed 23 years ago

nsCString::Replace is broken

Categories

(Core :: XPCOM, defect)

x86
Linux
defect
Not set
critical

Tracking

()

RESOLVED FIXED

People

(Reporter: darin.moz, Assigned: scc)

References

Details

Attachments

(1 file)

consider this sample program: #include "nsString.h" int main(int argc, char **argv) { nsCString foo; foo.Assign("abc"); printf("foo=[%s]\n", foo.get()); foo.Replace(1, 1, nsDependentCString(argv[1])); printf("foo=[%s]\n", foo.get()); return 0; } when i run it i get these results: % ./Test "" foo=[abc] foo=[ac] <== good % ./Test "f" foo=[abc] foo=[afc] <== good % ./Test "ff" foo=[abc] foo=[aff] <== oops! what happened to the 'c' % ./Test "fff" foo=[abc] foo=[afff] <== again, no 'c' seems like a bug, since scc says: <sccMtg> |Replace| is like a cut followed by an insert <sccMtg> |cutLength| is the length of the range to cut and in my example, |cutLength| is always 1.
Severity: normal → critical
if i substitute |Cut| + |Insert| for |Replace|, i get the correct results (ie. the 'c' isn't lost). this bug blocks my patch for bug 103916 (which is otherwise ready to land), so i'll likely replace all calls to |Replace| with |Cut| + |Insert| for now.
Attached patch v1.0 patchSplinter Review
*** Bug 108738 has been marked as a duplicate of this bug. ***
|copy_string_backward| was expecting the |WritingIterator| to point to the end of the section we wanted to write to, not the beginning, so we want to pass in |EndWriting()| (which after the SetLength will get us exactly what we want) instead of |BeginWriting().advance(replacementEnd)|.
Comment on attachment 56822 [details] [diff] [review] v1.0 patch r=darin
Attachment #56822 - Flags: review+
Comment on attachment 56822 [details] [diff] [review] v1.0 patch sr=scc
Fixed.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: