diff options
author | Christopher Ferris <cferris@google.com> | 2014-07-30 23:25:50 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-07-30 20:40:05 +0000 |
commit | 0f7ed163cf6c1fe6d71a1d7e5fb6d0989213be85 (patch) | |
tree | c182980fbe2b350af3760de535c3ea806eba3e8f | |
parent | 83b9826e683db30e9b359737253b87ef8b3ba3df (diff) | |
parent | e03e1eac0b7682884b6628df1305d34299680cb4 (diff) | |
download | android_bionic-0f7ed163cf6c1fe6d71a1d7e5fb6d0989213be85.tar.gz android_bionic-0f7ed163cf6c1fe6d71a1d7e5fb6d0989213be85.tar.bz2 android_bionic-0f7ed163cf6c1fe6d71a1d7e5fb6d0989213be85.zip |
Merge "Fix memchr with a zero length."
-rw-r--r-- | libc/arch-arm64/generic/bionic/memchr.S | 5 | ||||
-rw-r--r-- | tests/string_test.cpp | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/libc/arch-arm64/generic/bionic/memchr.S b/libc/arch-arm64/generic/bionic/memchr.S index fbb00caaa..e5ea57d8c 100644 --- a/libc/arch-arm64/generic/bionic/memchr.S +++ b/libc/arch-arm64/generic/bionic/memchr.S @@ -75,6 +75,7 @@ ENTRY(memchr) * Magic constant 0x40100401 allows us to identify which lane matches * the requested byte. */ + cbz cntin, .Lzero_length mov wtmp2, #0x0401 movk wtmp2, #0x4010, lsl #16 dup vrepchr.16b, chrin @@ -157,4 +158,8 @@ ENTRY(memchr) /* Select result or NULL */ csel result, xzr, result, eq ret + +.Lzero_length: + mov result, xzr + ret END(memchr) diff --git a/tests/string_test.cpp b/tests/string_test.cpp index bc2c05b40..73c94c602 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -763,6 +763,14 @@ TEST(string, memchr) { } } +TEST(string, memchr_zero) { + uint8_t* buffer; + ASSERT_EQ(0, posix_memalign(reinterpret_cast<void**>(&buffer), 64, 64)); + memset(buffer, 10, 64); + ASSERT_TRUE(NULL == memchr(buffer, 5, 0)); + ASSERT_TRUE(NULL == memchr(buffer, 10, 0)); +} + TEST(string, memrchr) { int seek_char = random() & 255; StringTestState<char> state(SMALL); |