[compiler-rt] [scudo] Apply filling option when realloc grows a block in-place too (PR #93212)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 16:09:31 PDT 2024


================
@@ -374,7 +384,18 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, PatternOrZeroFill) {
         else
           ASSERT_TRUE(V == scudo::PatternFillByte || V == 0);
       }
+
+      // Fill with a known pattern different from PatternFillByte.
       memset(P, 0xaa, Size);
+
+      // Shrink and then grow by one byte, verifying that it gets re-filled in
+      // the process. We assume that changing the size by just 1 is done in
+      // place.
+      ASSERT_EQ(Allocator->reallocate(P, Size - 1), P);
+      ASSERT_EQ(Allocator->reallocate(P, Size), P);
+      EXPECT_EQ((reinterpret_cast<unsigned char *>(P))[Size - 1],
+                scudo::PatternFillByte);
+
----------------
ChiaHungDuan wrote:

Right, I think we can utilize this test. BTW, it seems to me that the test has some problem. `ReallocSize - 32` only checks the constant range of memory with marker filled. We may want to do it like,

```
for (scudo::sptr Delta = -32; Delta < 32; Delta += 8) {
  // 1. memset(P, Marker, CurrentSize);
  // 2. Calculate NewSize and do the realloc
  // 3. Check the content needed to be preserved
  // 4. Check the in-place growing does fill the extended bytes
  }
  ```

https://github.com/llvm/llvm-project/pull/93212


More information about the llvm-commits mailing list