AddressSanitizer: get rid of limits.h, use constants for fixed size integral types instead.

llvm-svn: 151159
This commit is contained in:
Alexey Samsonov 2012-02-22 12:54:04 +00:00
parent abaf196be3
commit a5b3130e86
2 changed files with 20 additions and 5 deletions

View File

@ -24,7 +24,6 @@
#include "interception/interception.h"
#include <new>
#include <limits.h>
#if defined(_WIN32)
// FIXME: remove when we start intercepting on Windows. Currently it's needed to
@ -132,9 +131,9 @@ int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) {
nptr++;
}
while (IsDigit(*nptr)) {
res = (res <= ULLONG_MAX / 10) ? res * 10 : ULLONG_MAX;
res = (res <= UINT64_MAX / 10) ? res * 10 : UINT64_MAX;
int digit = ((*nptr) - '0');
res = (res <= ULLONG_MAX - digit) ? res + digit : ULLONG_MAX;
res = (res <= UINT64_MAX - digit) ? res + digit : UINT64_MAX;
have_digits = true;
nptr++;
}
@ -142,9 +141,9 @@ int64_t internal_simple_strtoll(const char *nptr, char **endptr, int base) {
*endptr = (have_digits) ? (char*)nptr : old_nptr;
}
if (sgn > 0) {
return (int64_t)(Min((uint64_t)LLONG_MAX, res));
return (int64_t)(Min((uint64_t)INT64_MAX, res));
} else {
return (res > LLONG_MAX) ? LLONG_MIN : ((int64_t)res * -1);
return (res > INT64_MAX) ? INT64_MIN : ((int64_t)res * -1);
}
}

View File

@ -59,6 +59,22 @@ extern "C" void* _ReturnAddress(void);
#endif
#endif
// Limits for integral types. We have to redefine it in case we don't
// have stdint.h (like in Visual Studio 9).
#if __WORDSIZE == 64
# define __INT64_C(c) c ## L
# define __UINT64_C(c) c ## UL
#else
# define __INT64_C(c) c ## LL
# define __UINT64_C(c) c ## ULL
#endif // __WORDSIZE == 64
# define INT32_MIN (-2147483647-1)
# define INT32_MAX (2147483647)
# define UINT32_MAX (4294967295U)
# define INT64_MIN (-__INT64_C(9223372036854775807)-1)
# define INT64_MAX (__INT64_C(9223372036854775807))
# define UINT64_MAX (__UINT64_C(18446744073709551615))
#if defined(__linux__)
# define ASAN_LINUX 1
#else