[compiler-rt] 0117619 - [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:36:18 PST 2023


Author: Kirill Stoimenov
Date: 2023-02-07T00:35:56Z
New Revision: 01176191d2fc3fd6807a362fec9702990a46a97c

URL: https://github.com/llvm/llvm-project/commit/01176191d2fc3fd6807a362fec9702990a46a97c
DIFF: https://github.com/llvm/llvm-project/commit/01176191d2fc3fd6807a362fec9702990a46a97c.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/test/hwasan/TestCases/malloc-test.c
    compiler-rt/test/hwasan/TestCases/new-test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/hwasan/TestCases/malloc-test.c b/compiler-rt/test/hwasan/TestCases/malloc-test.c
index 199464b9c3001..24fdfaae1da0f 100644
--- a/compiler-rt/test/hwasan/TestCases/malloc-test.c
+++ b/compiler-rt/test/hwasan/TestCases/malloc-test.c
@@ -11,6 +11,6 @@ int main() {
   __hwasan_enable_allocator_tagging();
   char *a1 = (char*)malloc(0);
   assert(a1 != 0);
-  assert(__sanitizer_get_allocated_size(a1) == 0);
+  assert(__sanitizer_get_allocated_size(a1) == 1);
   free(a1);
 }

diff  --git a/compiler-rt/test/hwasan/TestCases/new-test.cpp b/compiler-rt/test/hwasan/TestCases/new-test.cpp
index 7fd20f843d41f..184c0a69529cc 100644
--- a/compiler-rt/test/hwasan/TestCases/new-test.cpp
+++ b/compiler-rt/test/hwasan/TestCases/new-test.cpp
@@ -15,7 +15,7 @@ int main() {
   size_t volatile n = 0;
   char *a1 = new char[n];
   assert(a1 != nullptr);
-  assert(__sanitizer_get_allocated_size(a1) == 0);
+  assert(__sanitizer_get_allocated_size(a1) == 1);
   delete[] a1;
 
 #if defined(__cpp_aligned_new) &&                                              \


        


More information about the llvm-commits mailing list