[compiler-rt] r189797 - Add internal_strchrnul function
Alexey Samsonov
samsonov at google.com
Tue Sep 3 06:09:29 PDT 2013
Author: samsonov
Date: Tue Sep 3 08:09:28 2013
New Revision: 189797
URL: http://llvm.org/viewvc/llvm-project?rev=189797&view=rev
Log:
Add internal_strchrnul function
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc?rev=189797&r1=189796&r2=189797&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc Tue Sep 3 08:09:28 2013
@@ -125,6 +125,13 @@ char* internal_strchr(const char *s, int
}
}
+char *internal_strchrnul(const char *s, int c) {
+ char *res = internal_strchr(s, c);
+ if (!res)
+ res = (char*)s + internal_strlen(s);
+ return res;
+}
+
char *internal_strrchr(const char *s, int c) {
const char *res = 0;
for (uptr i = 0; s[i]; i++) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h?rev=189797&r1=189796&r2=189797&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Tue Sep 3 08:09:28 2013
@@ -32,6 +32,7 @@ void *internal_memmove(void *dest, const
// Should not be used in performance-critical places.
void *internal_memset(void *s, int c, uptr n);
char* internal_strchr(const char *s, int c);
+char *internal_strchrnul(const char *s, int c);
int internal_strcmp(const char *s1, const char *s2);
uptr internal_strcspn(const char *s, const char *reject);
char *internal_strdup(const char *s);
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc?rev=189797&r1=189796&r2=189797&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc Tue Sep 3 08:09:28 2013
@@ -115,3 +115,10 @@ TEST(SanitizerCommon, FileOps) {
internal_close(fd);
}
+TEST(SanitizerCommon, InternalStrFunctions) {
+ const char *haystack = "haystack";
+ EXPECT_EQ(haystack + 2, internal_strchr(haystack, 'y'));
+ EXPECT_EQ(haystack + 2, internal_strchrnul(haystack, 'y'));
+ EXPECT_EQ(0, internal_strchr(haystack, 'z'));
+ EXPECT_EQ(haystack + 8, internal_strchrnul(haystack, 'z'));
+}
More information about the llvm-commits
mailing list