diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-10-24 20:20:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-10-24 20:20:00 +0000 |
commit | b128c78aef290f0eb0a5fc989a53a39c89a131c9 (patch) | |
tree | 4f7c2e3c1e528c89c9e3eaaa80a5657b91850816 /libutils/Unicode.cpp | |
parent | 0f2097c0f03760080322705c5ef8fcc836cc6419 (diff) | |
parent | bf3fff1a9ed39d005f36db43c9893697e0a006a3 (diff) |
Merge "libutils: Fix bug in strstr16."
Diffstat (limited to 'libutils/Unicode.cpp')
-rw-r--r-- | libutils/Unicode.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp index 5fd915524..e7520a8e8 100644 --- a/libutils/Unicode.cpp +++ b/libutils/Unicode.cpp @@ -297,23 +297,22 @@ 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 { + const char16_t needle = *target; + if (needle == '\0') return (char16_t*)src; + + const size_t target_len = strlen16(++target); + do { do { - if (*src == '\0') { - return nullptr; - } + if (*src == '\0') { + return nullptr; + } } while (*src++ != needle); - } while (strncmp16(src, target, target_len) != 0); - src--; - } + } while (strncmp16(src, target, target_len) != 0); + src--; return (char16_t*)src; } - int strzcmp16(const char16_t *s1, size_t n1, const char16_t *s2, size_t n2) { const char16_t* e1 = s1+n1; |