[llvm-commits] [compiler-rt] r170274 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_allocator.h tests/sanitizer_allocator_test.cc

Kostya Serebryany kcc at google.com
Sat Dec 15 10:36:23 PST 2012


Author: kcc
Date: Sat Dec 15 12:36:23 2012
New Revision: 170274

URL: http://llvm.org/viewvc/llvm-project?rev=170274&view=rev
Log:
[sanitizer] fix a bug that has crept into the sanitizer allocator and caused SEGV on allocations between 1Mb and 2Mb, improve the test

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=170274&r1=170273&r2=170274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Sat Dec 15 12:36:23 2012
@@ -297,7 +297,7 @@
     uptr beg_idx = region->allocated_user;
     uptr end_idx = beg_idx + kPopulateSize;
     uptr region_beg = kSpaceBeg + kRegionSize * class_id;
-    if (end_idx > region->mapped_user) {
+    if (Max(end_idx, beg_idx + size) > region->mapped_user) {
       // Do the mmap for the user memory.
       CHECK_GT(region->mapped_user + kUserMapSize, end_idx);
       MapWithCallback(region_beg + region->mapped_user, kUserMapSize);

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc?rev=170274&r1=170273&r2=170274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc Sat Dec 15 12:36:23 2012
@@ -96,12 +96,15 @@
       uptr size = sizes[s];
       if (!a->CanAllocate(size, 1)) continue;
       // printf("s = %ld\n", size);
-      uptr n_iter = std::max((uptr)2, 1000000 / size);
+      uptr n_iter = std::max((uptr)6, 1000000 / size);
       for (uptr i = 0; i < n_iter; i++) {
-        void *x = a->Allocate(size, 1);
+        char *x = (char*)a->Allocate(size, 1);
+        x[0] = 0;
+        x[size - 1] = 0;
+        x[size / 2] = 0;
         allocated.push_back(x);
         CHECK_EQ(x, a->GetBlockBegin(x));
-        CHECK_EQ(x, a->GetBlockBegin((char*)x + size - 1));
+        CHECK_EQ(x, a->GetBlockBegin(x + size - 1));
         CHECK(a->PointerIsMine(x));
         CHECK_GE(a->GetActuallyAllocatedSize(x), size);
         uptr class_id = a->GetSizeClass(x);





More information about the llvm-commits mailing list