From ff1de6cc00b5edc95b676aff78a54e40bfa15219 Mon Sep 17 00:00:00 2001 From: Chia-hung Duan Date: Fri, 6 Dec 2024 07:11:33 +0000 Subject: [PATCH] [scudo] Clean the TODO in list.h * Finished the type and size verification * Remove the TODO for checking if array size can be fit into LinkTy because if there's a truncation happens, other DCHECK like offset checking will catch the failure. In addition, it's supposed to be a rare case. --- compiler-rt/lib/scudo/standalone/list.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler-rt/lib/scudo/standalone/list.h b/compiler-rt/lib/scudo/standalone/list.h index 5c34cbb049e60..e7c69e5bb88d6 100644 --- a/compiler-rt/lib/scudo/standalone/list.h +++ b/compiler-rt/lib/scudo/standalone/list.h @@ -48,10 +48,11 @@ class LinkOp { template class LinkOp { public: - using LinkTy = decltype(T::Next); + using LinkTy = typename assertSameType< + typename removeConst::type, + typename removeConst::type>::type; LinkOp() = default; - // TODO: Check if the `BaseSize` can fit in `Size`. LinkOp(T *BaseT, uptr BaseSize) : Base(BaseT), Size(static_cast(BaseSize)) {} void init(T *LinkBase, uptr BaseSize) { @@ -70,11 +71,12 @@ template class LinkOp { } // Set `X->Next` to `Next`. void setNext(T *X, T *Next) const { - // TODO: Check if the offset fits in the size of `LinkTy`. - if (Next == nullptr) + if (Next == nullptr) { X->Next = getEndOfListVal(); - else + } else { + DCHECK_LE(static_cast(Next - Base), Size); X->Next = static_cast(Next - Base); + } } T *getPrev(T *X) const { @@ -94,7 +96,6 @@ template class LinkOp { X->Prev = static_cast(Prev - Base); } - // TODO: `LinkTy` should be the same as decltype(T::EndOfListVal). LinkTy getEndOfListVal() const { return T::EndOfListVal; } protected: