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> {
74
74
if (Next == nullptr ) {
75
75
X->Next = getEndOfListVal ();
76
76
} else {
77
- DCHECK_LE ( static_cast <LinkTy>( Next - Base), Size );
77
+ assertElementInRange ( Next);
78
78
X->Next = static_cast <LinkTy>(Next - Base);
79
79
}
80
80
}
@@ -88,16 +88,22 @@ template <class T> class LinkOp<T, /*LinkWithPtr=*/false> {
88
88
}
89
89
// Set `X->Prev` to `Prev`.
90
90
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 ) {
94
92
X->Prev = getEndOfListVal ();
95
- else
93
+ } else {
94
+ assertElementInRange (Prev);
96
95
X->Prev = static_cast <LinkTy>(Prev - Base);
96
+ }
97
97
}
98
98
99
99
LinkTy getEndOfListVal () const { return T::EndOfListVal; }
100
100
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
+
101
107
protected:
102
108
T *Base = nullptr ;
103
109
LinkTy Size = 0 ;
You can’t perform that action at this time.
0 commit comments