summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-07-30 16:06:56 -0700
committerChristopher Ferris <cferris@google.com>2014-07-30 16:33:11 -0700
commit61833de613990f2fdaf357bb3d854d72a4980890 (patch)
tree53d49b24ccef4c4cddb9f37b869cf364bf5ea8ea /tests
parent4f76469e88e255bab1f8264e9ff8b95bff84365f (diff)
downloadbionic-61833de613990f2fdaf357bb3d854d72a4980890.zip
bionic-61833de613990f2fdaf357bb3d854d72a4980890.tar.gz
bionic-61833de613990f2fdaf357bb3d854d72a4980890.tar.bz2
Fix memchr with a zero length.
The memchr implementation for 64 bit fails if these conditions occur: - The buffer is 32 byte aligned. - The buffer contains the character in the first byte. - The count sent in is zero. The function should return NULL, but it's not. Bug: 16676625 (cherry picked from commit e03e1eac0b7682884b6628df1305d34299680cb4) Change-Id: Ie4cca2c445127a0936ee2b96651a8e7204fbaffd
Diffstat (limited to 'tests')
-rw-r--r--tests/string_test.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index bc2c05b..73c94c6 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);