diff options
author | Michael Wright <michaelwr@google.com> | 2016-05-16 21:23:07 +0100 |
---|---|---|
committer | Michael Wright <michaelwr@google.com> | 2016-05-16 21:23:07 +0100 |
commit | 0fd60eb9b4026bcbc3a075e6aa9264346bcc25d1 (patch) | |
tree | 65adab33efa2b91c69e38ee659e898efa6a2d359 /libutils/Unicode.cpp | |
parent | 8b452b876b90dcfff1dab9012b65b5e67c4531a4 (diff) | |
download | system_core-0fd60eb9b4026bcbc3a075e6aa9264346bcc25d1.tar.gz system_core-0fd60eb9b4026bcbc3a075e6aa9264346bcc25d1.tar.bz2 system_core-0fd60eb9b4026bcbc3a075e6aa9264346bcc25d1.zip |
Fix strstr16.
strcmp needs a limit, otherwise it will compare the null terminator
with the next character in the haystack, which results in the compare
failing for all searches except where the needle is found at the very
end.
Bug: 28663748
Change-Id: I1939dc4037c2f2a75d617943b063d2d38a8c5e3a
Diffstat (limited to 'libutils/Unicode.cpp')
-rw-r--r-- | libutils/Unicode.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp index ade896a02..f1f8bc939 100644 --- a/libutils/Unicode.cpp +++ b/libutils/Unicode.cpp @@ -292,6 +292,7 @@ size_t strnlen16(const char16_t *s, size_t maxlen) char16_t* strstr16(const char16_t* src, const char16_t* target) { const char16_t needle = *target++; + const size_t target_len = strlen16(target); if (needle != '\0') { do { do { @@ -299,7 +300,7 @@ char16_t* strstr16(const char16_t* src, const char16_t* target) return nullptr; } } while (*src++ != needle); - } while (strcmp16(src, target) != 0); + } while (strncmp16(src, target, target_len) != 0); src--; } |