[compiler-rt] [sanitizer] Make CHECKs in bitvector more precise (NFC) (PR #94630)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 08:33:22 PDT 2024


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/94630

These CHECKs are all checking indices, which must be strictly smaller than the size (otherwise they would go out of bounds).

>From 029eef3c1e6d29e2a4271cd76de5ee92e98dc49d Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 6 Jun 2024 17:28:17 +0200
Subject: [PATCH] [sanitizer] Make CHECKs in bitvector more precise (NFC)

These CHECKs are all checking indices, which must be strictly
smaller than the size (otherwise they would go out of bounds).
---
 compiler-rt/lib/sanitizer_common/sanitizer_bitvector.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_bitvector.h b/compiler-rt/lib/sanitizer_common/sanitizer_bitvector.h
index 07a59ab11c429..eef1e7e9d9570 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_bitvector.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_bitvector.h
@@ -321,23 +321,23 @@ class TwoLevelBitVector {
   };
 
  private:
-  void check(uptr idx) const { CHECK_LE(idx, size()); }
+  void check(uptr idx) const { CHECK_LT(idx, size()); }
 
   uptr idx0(uptr idx) const {
     uptr res = idx / (BV::kSize * BV::kSize);
-    CHECK_LE(res, kLevel1Size);
+    CHECK_LT(res, kLevel1Size);
     return res;
   }
 
   uptr idx1(uptr idx) const {
     uptr res = (idx / BV::kSize) % BV::kSize;
-    CHECK_LE(res, BV::kSize);
+    CHECK_LT(res, BV::kSize);
     return res;
   }
 
   uptr idx2(uptr idx) const {
     uptr res = idx % BV::kSize;
-    CHECK_LE(res, BV::kSize);
+    CHECK_LT(res, BV::kSize);
     return res;
   }
 



More information about the llvm-commits mailing list