File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
compiler-rt/lib/scudo/standalone Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
7474 if (Next == nullptr ) {
7575 X->Next = getEndOfListVal ();
7676 } else {
77- DCHECK_LE ( static_cast <LinkTy>( Next - Base), Size );
77+ assertElementInRange ( Next);
7878 X->Next = static_cast <LinkTy>(Next - Base);
7979 }
8080 }
@@ -88,16 +88,22 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
8888 }
8989 // Set `X->Prev` to `Prev`.
9090 void setPrev (T *X, T *Prev) const {
91- DCHECK_LT (reinterpret_cast <uptr>(Prev),
92- reinterpret_cast <uptr>(Base + Size));
93- if (Prev == nullptr )
91+ if (Prev == nullptr ) {
9492 X->Prev = getEndOfListVal ();
95- else
93+ } else {
94+ assertElementInRange (Prev);
9695 X->Prev = static_cast <LinkTy>(Prev - Base);
96+ }
9797 }
9898
9999 LinkTy getEndOfListVal () const { return T::EndOfListVal; }
100100
101+ private:
102+ void assertElementInRange (T *X) const {
103+ DCHECK_GE (reinterpret_cast <uptr>(X), reinterpret_cast <uptr>(Base));
104+ DCHECK_LE (static_cast <LinkTy>(X - Base), Size);
105+ }
106+
101107protected:
102108 T *Base = nullptr ;
103109 LinkTy Size = 0 ;
You can’t perform that action at this time.
0 commit comments