Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Issue 2979393002: [string_util] fix bug in ReplaceSubstringsAfterOffset() (Closed)

Created:
3 years, 5 months ago by ncarter (slow)
Modified:
3 years, 4 months ago
Reviewers:
danakj, Peter Kasting
CC:
chromium-reviews, danakj+watch_chromium.org, jshin+watch_chromium.org, vmpstr+watch_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

[string_util] fix bug in ReplaceSubstringsAfterOffset() The problem with DoReplaceSubstringsAfterOffset was that the following search would not terminate: ReplaceSubstringsAfterOffset(std::string("aaabaa"), 0, "aa", "ccc"); The root cause of this is an algorithmic bug, where it was assumed that string::rfind and string::find would return the same matches in reversed order. The fix is to only scan forward using find(). For the length-expansion case, if capacity is insufficient, we swap with a temporary and build the result into new memory. If existing capacity suffices, we'll shift the tail of the string down to the new size, and then use left-to-right memmove loop of the length- contraction case, with the shifted tail as the src. BUG=749228 Review-Url: https://codereview.chromium.org/2979393002 Cr-Commit-Position: refs/heads/master@{#491170} Committed: https://chromium.googlesource.com/chromium/src/+/09d9682b0039e3b1dd16e5be60f5ebe4f698021f

Patch Set 1 #

Patch Set 2 : Substring replacement. #

Patch Set 3 : Change upstream #

Patch Set 4 : Support in-place expansion if capacity is available #

Patch Set 5 : StringPiece #

Patch Set 6 : typename #

Patch Set 7 : ReplaceCharsT #

Patch Set 8 : Reduce scope of change to just correctness fix. #

Total comments: 56

Patch Set 9 : Things. #

Patch Set 10 : preincrement. #

Patch Set 11 : Scratch. #

Patch Set 12 : Unittest fixes. #

Total comments: 15

Patch Set 13 : pkasting fixes #

Patch Set 14 : typename for clang #

Patch Set 15 : npos. #

Patch Set 16 : str_length #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+168 lines, -97 lines) Patch
M base/strings/string_util.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +111 lines, -74 lines 3 comments Download
M base/strings/string_util_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +57 lines, -23 lines 0 comments Download

Messages

Total messages: 73 (54 generated)
ncarter (slow)
Peter, Dana -- Please review this bug fix https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if ...
3 years, 4 months ago (2017-07-26 23:50:14 UTC) #33
Peter Kasting
It seems like the non-termination issue was because of the "if (current_match == first_match) return;" ...
3 years, 4 months ago (2017-07-27 01:09:57 UTC) #34
Peter Kasting
LGTM https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (left): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#oldcode783 base/strings/string_util.cc:783: // as we're reading it, needing to shift, ...
3 years, 4 months ago (2017-07-27 05:25:14 UTC) #35
danakj
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode745 base/strings/string_util.cc:745: find_this.length()); nit: this could be written find_length? https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode760 base/strings/string_util.cc:760: ...
3 years, 4 months ago (2017-07-27 15:55:29 UTC) #38
danakj
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/27 15:55:30, danakj ...
3 years, 4 months ago (2017-07-27 15:58:48 UTC) #39
Peter Kasting
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { I don't think memmove() ...
3 years, 4 months ago (2017-07-27 22:09:47 UTC) #40
Peter Kasting
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/27 22:09:47, Peter ...
3 years, 4 months ago (2017-07-27 22:11:21 UTC) #41
ncarter (slow)
ptal https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (left): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#oldcode783 base/strings/string_util.cc:783: // as we're reading it, needing to shift, ...
3 years, 4 months ago (2017-07-28 02:34:26 UTC) #44
Peter Kasting
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/28 02:34:25, ncarter ...
3 years, 4 months ago (2017-07-28 08:29:25 UTC) #47
danakj
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/28 08:29:24, Peter ...
3 years, 4 months ago (2017-07-28 15:53:49 UTC) #48
ncarter (slow)
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/28 08:29:24, Peter ...
3 years, 4 months ago (2017-07-28 21:46:34 UTC) #55
danakj
I'll be away monday so won't get to look at this again for a little ...
3 years, 4 months ago (2017-07-28 22:00:28 UTC) #56
Peter Kasting
LGTM https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/28 21:46:34, ...
3 years, 4 months ago (2017-07-29 02:18:01 UTC) #57
ncarter (slow)
https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/140001/base/strings/string_util.cc#newcode768 base/strings/string_util.cc:768: if (str->capacity() < final_length) { On 2017/07/29 02:18:01, Peter ...
3 years, 4 months ago (2017-07-31 18:55:39 UTC) #62
danakj
LGTM https://codereview.chromium.org/2979393002/diff/300001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/300001/base/strings/string_util.cc#newcode855 base/strings/string_util.cc:855: // If we're shortening the string, truncate it ...
3 years, 4 months ago (2017-08-01 19:55:55 UTC) #65
Peter Kasting
https://codereview.chromium.org/2979393002/diff/300001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/300001/base/strings/string_util.cc#newcode855 base/strings/string_util.cc:855: // If we're shortening the string, truncate it now. ...
3 years, 4 months ago (2017-08-01 19:59:21 UTC) #66
danakj
https://codereview.chromium.org/2979393002/diff/300001/base/strings/string_util.cc File base/strings/string_util.cc (right): https://codereview.chromium.org/2979393002/diff/300001/base/strings/string_util.cc#newcode855 base/strings/string_util.cc:855: // If we're shortening the string, truncate it now. ...
3 years, 4 months ago (2017-08-01 20:00:37 UTC) #67
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2979393002/300001
3 years, 4 months ago (2017-08-01 22:21:57 UTC) #70
commit-bot: I haz the power
3 years, 4 months ago (2017-08-02 00:31:38 UTC) #73
Message was sent while issue was closed.
Committed patchset #16 (id:300001) as
https://chromium.googlesource.com/chromium/src/+/09d9682b0039e3b1dd16e5be60f5...

Powered by Google App Engine
This is Rietveld 408576698