[compiler-rt] c6ea5b0 - [HWASAN] Modify HwasanAllocate to set the size to 1 if requested size is 0

Kirill Stoimenov via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 16:01:30 PST 2023


Author: Kirill Stoimenov
Date: 2023-02-07T00:01:20Z
New Revision: c6ea5b0cd1728a044a4c5b3c8f1bf35e1d8d2847

URL: https://github.com/llvm/llvm-project/commit/c6ea5b0cd1728a044a4c5b3c8f1bf35e1d8d2847
DIFF: https://github.com/llvm/llvm-project/commit/c6ea5b0cd1728a044a4c5b3c8f1bf35e1d8d2847.diff

LOG: [HWASAN] Modify HwasanAllocate to set the size to 1 if requested size is 0

This should keep it consistent with LSAN and ASAN,

Reviewed By: vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D143438

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_allocator.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index 9373ea2d6bad..ec52741e3fd6 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -163,7 +163,7 @@ static uptr TaggedSize(uptr size) {
 static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
                             bool zeroise) {
   // Keep this consistent with LSAN and ASAN behavior.
-  if (orig_size == 0)
+  if (UNLIKELY(orig_size == 0))
     orig_size = 1;
   if (orig_size > kMaxAllowedMallocSize) {
     if (AllocatorMayReturnNull()) {


        


More information about the llvm-commits mailing list