diff options
author | iceman <iceman@yandex-team.ru> | 2014-10-06 02:15:28 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-06 09:16:11 +0000 |
commit | 374140066ed0c22b2b9dc3f64a61e6ecf4fcd2c6 (patch) | |
tree | e539ce606917f5e287f07aa3b7a9c91263dee972 /base/i18n/break_iterator.cc | |
parent | bf6897a84c8a7f08e4c2cd8506b833d93a504ab8 (diff) | |
download | chromium_src-374140066ed0c22b2b9dc3f64a61e6ecf4fcd2c6.zip chromium_src-374140066ed0c22b2b9dc3f64a61e6ecf4fcd2c6.tar.gz chromium_src-374140066ed0c22b2b9dc3f64a61e6ecf4fcd2c6.tar.bz2 |
Fix bug in BreakIterator class that could cause illegal access
after setting new content by calling SetText function.
Public function SetText() couldn't update internal string
because it was a const reference.
Used StringPiece16 to fix.
BUG=411213
TEST=base_unittests --gtest_filter="BreakIteratorTest.GetStringAfterSetText"
Review URL: https://codereview.chromium.org/545113002
Cr-Commit-Position: refs/heads/master@{#298207}
Diffstat (limited to 'base/i18n/break_iterator.cc')
-rw-r--r-- | base/i18n/break_iterator.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/base/i18n/break_iterator.cc b/base/i18n/break_iterator.cc index 89b1d0f..e3aaa2b 100644 --- a/base/i18n/break_iterator.cc +++ b/base/i18n/break_iterator.cc @@ -14,7 +14,7 @@ namespace i18n { const size_t npos = static_cast<size_t>(-1); -BreakIterator::BreakIterator(const string16& str, BreakType break_type) +BreakIterator::BreakIterator(const StringPiece16& str, BreakType break_type) : iter_(NULL), string_(str), break_type_(break_type), @@ -22,7 +22,7 @@ BreakIterator::BreakIterator(const string16& str, BreakType break_type) pos_(0) { } -BreakIterator::BreakIterator(const string16& str, const string16& rules) +BreakIterator::BreakIterator(const StringPiece16& str, const string16& rules) : iter_(NULL), string_(str), rules_(rules), @@ -132,6 +132,7 @@ bool BreakIterator::SetText(const base::char16* text, const size_t length) { NOTREACHED() << "ubrk_setText failed"; return false; } + string_ = StringPiece16(text, length); return true; } @@ -172,6 +173,10 @@ bool BreakIterator::IsGraphemeBoundary(size_t position) const { } string16 BreakIterator::GetString() const { + return GetStringPiece().as_string(); +} + +StringPiece16 BreakIterator::GetStringPiece() const { DCHECK(prev_ != npos && pos_ != npos); return string_.substr(prev_, pos_ - prev_); } |