libc: cleanup strchr
Move strchr to a .cpp file, and change to bionic directory.
Change-Id: I64ade7df326c0a9a714aca4caf5647b6833b1c97
diff --git a/tests/fortify2_test.cpp b/tests/fortify2_test.cpp
index 09c094c..ea890fe 100644
--- a/tests/fortify2_test.cpp
+++ b/tests/fortify2_test.cpp
@@ -45,6 +45,15 @@
}
#if __BIONIC__
+TEST(Fortify2_DeathTest, strchr_fortified2) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ foo myfoo;
+ memcpy(myfoo.a, "0123456789", sizeof(myfoo.a));
+ myfoo.b[0] = '\0';
+ ASSERT_EXIT(printf("%s", strchr(myfoo.a, 'a')),
+ testing::KilledBySignal(SIGSEGV), "");
+}
+
TEST(Fortify2_DeathTest, strrchr_fortified2) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index eb10c16..63bfadb 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -209,6 +209,13 @@
}
}
+TEST(string, strchr_with_0) {
+ char buf[10];
+ const char* s = "01234";
+ memcpy(buf, s, strlen(s) + 1);
+ EXPECT_TRUE(strchr(buf, '\0') == (buf + strlen(s)));
+}
+
TEST(string, strchr) {
int seek_char = random() & 255;