Skip to content

Commit aac000a

Browse files
authored
[scudo] Clean the TODO in list.h (#119323)
* 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.
1 parent 78c2b6d commit aac000a

File tree

1 file changed

+7
-6
lines changed
  • compiler-rt/lib/scudo/standalone

1 file changed

+7
-6
lines changed

compiler-rt/lib/scudo/standalone/list.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ class LinkOp {
4848

4949
template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
5050
public:
51-
using LinkTy = decltype(T::Next);
51+
using LinkTy = typename assertSameType<
52+
typename removeConst<decltype(T::Next)>::type,
53+
typename removeConst<decltype(T::EndOfListVal)>::type>::type;
5254

5355
LinkOp() = default;
54-
// TODO: Check if the `BaseSize` can fit in `Size`.
5556
LinkOp(T *BaseT, uptr BaseSize)
5657
: Base(BaseT), Size(static_cast<LinkTy>(BaseSize)) {}
5758
void init(T *LinkBase, uptr BaseSize) {
@@ -70,11 +71,12 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
7071
}
7172
// Set `X->Next` to `Next`.
7273
void setNext(T *X, T *Next) const {
73-
// TODO: Check if the offset fits in the size of `LinkTy`.
74-
if (Next == nullptr)
74+
if (Next == nullptr) {
7575
X->Next = getEndOfListVal();
76-
else
76+
} else {
77+
DCHECK_LE(static_cast<LinkTy>(Next - Base), Size);
7778
X->Next = static_cast<LinkTy>(Next - Base);
79+
}
7880
}
7981

8082
T *getPrev(T *X) const {
@@ -94,7 +96,6 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
9496
X->Prev = static_cast<LinkTy>(Prev - Base);
9597
}
9698

97-
// TODO: `LinkTy` should be the same as decltype(T::EndOfListVal).
9899
LinkTy getEndOfListVal() const { return T::EndOfListVal; }
99100

100101
protected:

0 commit comments

Comments
 (0)