[llvm-commits] [compiler-rt] r147807 - in /compiler-rt/trunk/lib/asan: asan_interceptors.cc asan_interceptors.h asan_rtl.cc
Kostya Serebryany
kcc at google.com
Mon Jan 9 14:20:49 PST 2012
Author: kcc
Date: Mon Jan 9 16:20:49 2012
New Revision: 147807
URL: http://llvm.org/viewvc/llvm-project?rev=147807&view=rev
Log:
[asan] don't use strstr/strncat from libc, use our own versions instead
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
compiler-rt/trunk/lib/asan/asan_interceptors.h
compiler-rt/trunk/lib/asan/asan_rtl.cc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=147807&r1=147806&r2=147807&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Mon Jan 9 16:20:49 2012
@@ -162,6 +162,26 @@
return 0;
}
+char *internal_strstr(const char *haystack, const char *needle) {
+ // This is O(N^2), but we are not using it in hot places.
+ size_t len1 = internal_strlen(haystack);
+ size_t len2 = internal_strlen(needle);
+ if (len1 < len2) return 0;
+ for (size_t pos = 0; pos <= len1 - len2; pos++) {
+ if (internal_memcmp(haystack + pos, needle, len2) == 0)
+ return (char*)haystack + pos;
+ }
+ return 0;
+}
+
+char *internal_strncat(char *dst, const char *src, size_t n) {
+ size_t len = internal_strlen(dst);
+ size_t i;
+ for (i = 0; i < n && src[i]; i++)
+ dst[len + i] = src[i];
+ dst[len + i] = 0;
+ return dst;
+}
} // namespace __asan
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=147807&r1=147806&r2=147807&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Mon Jan 9 16:20:49 2012
@@ -113,6 +113,9 @@
size_t internal_strnlen(const char *s, size_t maxlen);
void* internal_memchr(const void* s, int c, size_t n);
int internal_memcmp(const void* s1, const void* s2, size_t n);
+char *internal_strstr(const char *haystack, const char *needle);
+char *internal_strncat(char *dst, const char *src, size_t n);
+
// Initializes pointers to str*/mem* functions.
void InitializeAsanInterceptors();
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=147807&r1=147806&r2=147807&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Jan 9 16:20:49 2012
@@ -24,8 +24,6 @@
#include "asan_thread.h"
#include "asan_thread_registry.h"
-#include <string.h>
-
namespace __asan {
// -------------------------- Flags ------------------------- {{{1
@@ -172,8 +170,9 @@
const char *name_end = real_strchr(frame_descr, ' ');
CHECK(name_end);
buf[0] = 0;
- strncat(buf, frame_descr,
- Min(kBufSize, static_cast<intptr_t>(name_end - frame_descr)));
+ internal_strncat(buf, frame_descr,
+ Min(kBufSize,
+ static_cast<intptr_t>(name_end - frame_descr)));
Printf("Address %p is located at offset %ld "
"in frame <%s> of T%d's stack:\n",
addr, offset, buf, t->tid());
@@ -196,7 +195,7 @@
}
p++;
buf[0] = 0;
- strncat(buf, p, Min(kBufSize, len));
+ internal_strncat(buf, p, Min(kBufSize, len));
p += len;
Printf(" [%ld, %ld) '%s'\n", beg, beg + size, buf);
}
@@ -269,7 +268,7 @@
static int64_t IntFlagValue(const char *flags, const char *flag,
int64_t default_val) {
if (!flags) return default_val;
- const char *str = strstr(flags, flag);
+ const char *str = internal_strstr(flags, flag);
if (!str) return default_val;
return atoll(str + internal_strlen(flag));
}
More information about the llvm-commits
mailing list