[compiler-rt] [scudo] Minor refactor on element address validation (NFC) (PR #119436)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 11:17:57 PST 2024
https://github.com/ChiaHungDuan created https://github.com/llvm/llvm-project/pull/119436
None
>From 61d086ef46159be6d603144b4c057ff6469ee3b7 Mon Sep 17 00:00:00 2001
From: Chia-hung Duan <chiahungduan at google.com>
Date: Tue, 10 Dec 2024 19:16:42 +0000
Subject: [PATCH] [scudo] Minor refactor on element address validation (NFC)
---
compiler-rt/lib/scudo/standalone/list.h | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/list.h b/compiler-rt/lib/scudo/standalone/list.h
index e7c69e5bb88d67..e0b82788251b7f 100644
--- a/compiler-rt/lib/scudo/standalone/list.h
+++ b/compiler-rt/lib/scudo/standalone/list.h
@@ -74,7 +74,7 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
if (Next == nullptr) {
X->Next = getEndOfListVal();
} else {
- DCHECK_LE(static_cast<LinkTy>(Next - Base), Size);
+ assertElementInRange(Next);
X->Next = static_cast<LinkTy>(Next - Base);
}
}
@@ -88,16 +88,22 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
}
// Set `X->Prev` to `Prev`.
void setPrev(T *X, T *Prev) const {
- DCHECK_LT(reinterpret_cast<uptr>(Prev),
- reinterpret_cast<uptr>(Base + Size));
- if (Prev == nullptr)
+ if (Prev == nullptr) {
X->Prev = getEndOfListVal();
- else
+ } else {
+ assertElementInRange(Prev);
X->Prev = static_cast<LinkTy>(Prev - Base);
+ }
}
LinkTy getEndOfListVal() const { return T::EndOfListVal; }
+private:
+ void assertElementInRange(T *X) const {
+ DCHECK_GE(reinterpret_cast<uptr>(X), reinterpret_cast<uptr>(Base));
+ DCHECK_LE(static_cast<LinkTy>(X - Base), Size);
+ }
+
protected:
T *Base = nullptr;
LinkTy Size = 0;
More information about the llvm-commits
mailing list