[compiler-rt] b40908e - [NFC][scudo] Avoid integer overflow in test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 3 00:08:51 PDT 2021


Author: Vitaly Buka
Date: 2021-06-03T00:08:41-07:00
New Revision: b40908e639b6075c77d7b2a990a2a273a39f4102

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

LOG: [NFC][scudo] Avoid integer overflow in test

releasePagesToOS may shrink RSS below the value stored on start.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
index d8184a72361f2..711e3b28e31b2 100644
--- a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
@@ -37,16 +37,16 @@ TEST(ScudoCommonTest, SKIP_ON_FUCHSIA(ResidentMemorySize)) {
   MapPlatformData Data = {};
   void *P = map(nullptr, Size, "ResidentMemorySize", 0, &Data);
   ASSERT_NE(nullptr, P);
-  EXPECT_LT(getResidentMemorySize() - OnStart, Threshold);
+  EXPECT_LT(getResidentMemorySize(), OnStart + Threshold);
 
   memset(P, 1, Size);
-  EXPECT_GT(getResidentMemorySize() - OnStart, Size - Threshold);
+  EXPECT_GT(getResidentMemorySize(), OnStart + Size - Threshold);
 
   releasePagesToOS((uptr)P, 0, Size, &Data);
-  EXPECT_LT(getResidentMemorySize() - OnStart, Threshold);
+  EXPECT_LT(getResidentMemorySize(), OnStart + Threshold);
 
   memset(P, 1, Size);
-  EXPECT_GT(getResidentMemorySize() - OnStart, Size - Threshold);
+  EXPECT_GT(getResidentMemorySize(), OnStart + Size - Threshold);
 
   unmap(P, Size, 0, &Data);
 }


        


More information about the llvm-commits mailing list