summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2013-01-25 12:22:21 +0000
committerKostya Serebryany <kcc@google.com>2013-01-25 12:22:21 +0000
commitc1056f90ae31eab1e42b83108520b96c62e8b726 (patch)
tree5fd280cb95684598e47bf5b7e16b9a484a136e45 /compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
parentfa79cd65e2a08979c0d76b6f0dec6192161e5611 (diff)
downloadbcm5719-llvm-c1056f90ae31eab1e42b83108520b96c62e8b726.tar.gz
bcm5719-llvm-c1056f90ae31eab1e42b83108520b96c62e8b726.zip
[sanitizer] improve the calloc overflow check (spotted by samsonov@)
llvm-svn: 173443
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
index 26baf73a1f3..88a3a1b2569 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
@@ -76,8 +76,9 @@ void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback) {
}
bool CallocShouldReturnNullDueToOverflow(uptr size, uptr n) {
- uptr mul = size * n;
- return mul < size || mul < n;
+ if (!size) return false;
+ uptr max = (uptr)-1L;
+ return (max / size) < n;
}
} // namespace __sanitizer
OpenPOWER on IntegriCloud