[PATCH] [sanitizer] Fix overflow in SizeClassAllocator64::GetChunkIdx().

Sergey Matveev earthdok at google.com
Wed May 15 12:12:55 PDT 2013


Hi kcc, glider,

The 32-bit offset overflowed when more than 4GB was allocated in a size
class. Also removed the misleading comment.

http://llvm-reviews.chandlerc.com/D797

Files:
  lib/sanitizer_common/sanitizer_allocator.h

Index: lib/sanitizer_common/sanitizer_allocator.h
===================================================================
--- lib/sanitizer_common/sanitizer_allocator.h
+++ lib/sanitizer_common/sanitizer_allocator.h
@@ -492,11 +492,7 @@
   }
 
   static uptr GetChunkIdx(uptr chunk, uptr size) {
-    u32 offset = chunk % kRegionSize;
-    // Here we divide by a non-constant. This is costly.
-    // We require that kRegionSize is at least 2^32 so that offset is 32-bit.
-    // We save 2x by using 32-bit div, but may need to use a 256-way switch.
-    return offset / (u32)size;
+    return (chunk % kRegionSize) / size;
   }
 
   NOINLINE Batch* PopulateFreeList(AllocatorStats *stat, AllocatorCache *c,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D797.1.patch
Type: text/x-patch
Size: 704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130515/9db8cc59/attachment.bin>


More information about the llvm-commits mailing list