aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-02-29 20:00:39 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-02-29 20:00:39 +0900
commit4a888024476b76f8ad7e10266ce179f0fc8af077 (patch)
tree004b44f32721e3518e1c7fd36af7ef707e96d0ee
parent01406297a23201b3f99dfb316e7bb4e64b0472c3 (diff)
downloadplatform_build_kati-4a888024476b76f8ad7e10266ce179f0fc8af077.tar.gz
platform_build_kati-4a888024476b76f8ad7e10266ce179f0fc8af077.tar.bz2
platform_build_kati-4a888024476b76f8ad7e10266ce179f0fc8af077.zip
[C++] Honor string length in FindEndOfLine
When the character after the string is a backslash, FindOfLine returned a wrong length.
-rw-r--r--strutil.cc4
-rw-r--r--strutil_test.cc3
2 files changed, 6 insertions, 1 deletions
diff --git a/strutil.cc b/strutil.cc
index 9d37052..d3c14d8 100644
--- a/strutil.cc
+++ b/strutil.cc
@@ -427,6 +427,10 @@ size_t FindEndOfLine(StringPiece s, size_t e, size_t* lf_cnt) {
static const char ranges[] = "\0\0\n\n\\\\";
while (e < s.size()) {
e += SkipUntilSSE42(s.data() + e, s.size() - e, ranges, 6);
+ if (e >= s.size()) {
+ CHECK(s.size() == e);
+ break;
+ }
char c = s[e];
if (c == '\0')
break;
diff --git a/strutil_test.cc b/strutil_test.cc
index 960c89a..a89786f 100644
--- a/strutil_test.cc
+++ b/strutil_test.cc
@@ -133,8 +133,9 @@ void TestEscapeShell() {
void TestFindEndOfLine() {
size_t lf_cnt = 0;
ASSERT_EQ(FindEndOfLine("foo", 0, &lf_cnt), 3);
- char buf[10] = {'f', 'o', 'o', '\0', 'x', 'y'};
+ char buf[10] = {'f', 'o', '\\', '\0', 'x', 'y'};
ASSERT_EQ(FindEndOfLine(StringPiece(buf, 6), 0, &lf_cnt), 3);
+ ASSERT_EQ(FindEndOfLine(StringPiece(buf, 2), 0, &lf_cnt), 2);
}
} // namespace