[compiler-rt] b208088 - scudo: Limit the number of bytes tested in a realloc test.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 10:33:13 PST 2019


Author: Peter Collingbourne
Date: 2019-11-27T10:32:34-08:00
New Revision: b208088a2111aeb805d0984a2ff86b3ce14c725a

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

LOG: scudo: Limit the number of bytes tested in a realloc test.

This test was previously effectively doing:
P = malloc(X); write X bytes to P; P = realloc(P, X - Y); P = realloc(P, X)
and expecting that all X bytes stored to P would still be identical after
the final realloc.

This happens to be true for the current scudo implementation of realloc,
but is not guaranteed to be true by the C standard ("Any bytes in the new
object beyond the size of the old object have indeterminate values.").
This implementation detail will change with the new memory tagging support,
which unconditionally zeros newly allocated granules when memory tagging
is enabled. Fix this by limiting the number of bytes that we test to the
minimum size that we realloc the allocation to.

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

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/tests/combined_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index 849fa713ad1d..f38e9826863b 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -111,7 +111,7 @@ template <class Config> static void testAllocator() {
     const scudo::uptr NewSize = DataSize + Delta;
     void *NewP = Allocator->reallocate(P, NewSize);
     EXPECT_EQ(NewP, P);
-    for (scudo::uptr I = 0; I < scudo::Min(DataSize, NewSize); I++)
+    for (scudo::uptr I = 0; I < DataSize - 32; I++)
       EXPECT_EQ((reinterpret_cast<char *>(NewP))[I], Marker);
   }
   Allocator->deallocate(P, Origin);


        


More information about the llvm-commits mailing list