[llvm-commits] PATCH: Remove calls to library strtol/atoll from ASan RTL (issue 5656075)
samsonov at google.com
samsonov at google.com
Thu Feb 16 06:30:25 PST 2012
Reviewers: ramosian.glider, Evgeniy Stepanov,
Please review this at http://codereview.appspot.com/5656075/
Affected files:
M asan_interceptors.cc
M asan_interceptors.h
M asan_rtl.cc
-------------- next part --------------
Index: asan_rtl.cc
===================================================================
--- asan_rtl.cc (revision 150667)
+++ asan_rtl.cc (working copy)
@@ -172,16 +172,16 @@
addr, offset, buf, t->tid());
// Report the number of stack objects.
char *p;
- size_t n_objects = strtol(name_end, &p, 10);
+ size_t n_objects = internal_simple_strtoll(name_end, &p, 10);
CHECK(n_objects > 0);
Printf(" This frame has %ld object(s):\n", n_objects);
// Report all objects in this frame.
for (size_t i = 0; i < n_objects; i++) {
size_t beg, size;
intptr_t len;
- beg = strtol(p, &p, 10);
- size = strtol(p, &p, 10);
- len = strtol(p, &p, 10);
+ beg = internal_simple_strtoll(p, &p, 10);
+ size = internal_simple_strtoll(p, &p, 10);
+ len = internal_simple_strtoll(p, &p, 10);
if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') {
Printf("AddressSanitizer can't parse the stack frame descriptor: |%s|\n",
frame_descr);
@@ -258,20 +258,12 @@
}
// -------------------------- Init ------------------- {{{1
-#if defined(_WIN32)
-// atoll is not defined on Windows.
-int64_t atoll(const char *str) {
- UNIMPLEMENTED();
- return -1;
-}
-#endif
-
static int64_t IntFlagValue(const char *flags, const char *flag,
int64_t default_val) {
if (!flags) return default_val;
const char *str = internal_strstr(flags, flag);
if (!str) return default_val;
- return atoll(str + internal_strlen(flag));
+ return internal_atoll(str + internal_strlen(flag));
}
static void asan_atexit() {
Index: asan_interceptors.cc
===================================================================
--- asan_interceptors.cc (revision 150683)
+++ asan_interceptors.cc (working copy)
@@ -102,6 +102,32 @@
} \
} while (0)
+int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) {
+ CHECK(base == 10);
+ while (isspace(*nptr)) nptr++;
+ int sgn = 1;
+ int64_t res = 0;
+ if (*nptr == '+') {
+ sgn = 1;
+ nptr++;
+ } else if (*nptr == '-') {
+ sgn = -1;
+ nptr++;
+ }
+ while (isdigit(*nptr)) {
+ res = (res * 10) + ((*nptr) - '0');
+ nptr++;
+ }
+ if (endptr != NULL) {
+ *endptr = (char*)nptr;
+ }
+ return res * sgn;
+}
+
+int64_t internal_atoll(const char *nptr) {
+ return internal_simple_strtoll(nptr, (char**)NULL, 10);
+}
+
size_t internal_strlen(const char *s) {
size_t i = 0;
while (s[i]) i++;
Index: asan_interceptors.h
===================================================================
--- asan_interceptors.h (revision 150683)
+++ asan_interceptors.h (working copy)
@@ -29,6 +29,7 @@
namespace __asan {
// __asan::internal_X() is the implementation of X() for use in RTL.
+int64_t internal_atoll(const char *nptr);
size_t internal_strlen(const char *s);
size_t internal_strnlen(const char *s, size_t maxlen);
char* internal_strchr(const char *s, int c);
@@ -37,6 +38,8 @@
char *internal_strstr(const char *haystack, const char *needle);
char *internal_strncat(char *dst, const char *src, size_t n);
int internal_strcmp(const char *s1, const char *s2);
+// Works only for base=10 and doesn't check overflow.
+int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base);
void InitializeAsanInterceptors();
More information about the llvm-commits
mailing list