Closed
Bug 108734
Opened 23 years ago
Closed 23 years ago
nsCString::Replace is broken
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: darin.moz, Assigned: scc)
References
Details
Attachments
(1 file)
1.77 KB,
patch
|
darin.moz
:
review+
|
Details | Diff | Splinter Review |
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.
Reporter | ||
Updated•23 years ago
|
Severity: normal → critical
Reporter | ||
Comment 1•23 years ago
|
||
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.
Reporter | ||
Comment 2•23 years ago
|
||
Comment 3•23 years ago
|
||
*** Bug 108738 has been marked as a duplicate of this bug. ***
Comment 4•23 years ago
|
||
|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)|.
Reporter | ||
Comment 5•23 years ago
|
||
Comment on attachment 56822 [details] [diff] [review]
v1.0 patch
r=darin
Attachment #56822 -
Flags: review+
Assignee | ||
Comment 6•23 years ago
|
||
Comment on attachment 56822 [details] [diff] [review]
v1.0 patch
sr=scc
Updated•4 years ago
|
Component: String → XPCOM
You need to log in
before you can comment on or make changes to this bug.
Description
•