[HWASAN] Modify HwasanAllocate to set the size to 1 if requested size is 0
authorKirill Stoimenov <kstoimenov@google.com>
Mon, 6 Feb 2023 23:53:48 +0000 (23:53 +0000)
committerKirill Stoimenov <kstoimenov@google.com>
Tue, 7 Feb 2023 00:01:20 +0000 (00:01 +0000)
This should keep it consistent with LSAN and ASAN,

Reviewed By: vitalybuka, MaskRay

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

compiler-rt/lib/hwasan/hwasan_allocator.cpp

index 9373ea2..ec52741 100644 (file)
@@ -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()) {