File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -190,11 +190,16 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);
190
190
void
191
191
_PyFrame_LocalsToFast (_PyInterpreterFrame * frame , int clear );
192
192
193
-
194
193
static inline bool
195
194
_PyThreadState_HasStackSpace (PyThreadState * tstate , int size )
196
195
{
197
- return tstate -> datastack_top + size < tstate -> datastack_limit ;
196
+ assert (
197
+ (tstate -> datastack_top == NULL && tstate -> datastack_limit == NULL )
198
+ ||
199
+ (tstate -> datastack_top != NULL && tstate -> datastack_limit != NULL )
200
+ );
201
+ return tstate -> datastack_top != NULL &&
202
+ size < tstate -> datastack_limit - tstate -> datastack_top ;
198
203
}
199
204
200
205
extern _PyInterpreterFrame *
Original file line number Diff line number Diff line change
1
+ Remove two cases of undefined behavoir, by adding NULL checks.
Original file line number Diff line number Diff line change @@ -2195,15 +2195,12 @@ _PyInterpreterFrame *
2195
2195
_PyThreadState_PushFrame (PyThreadState * tstate , size_t size )
2196
2196
{
2197
2197
assert (size < INT_MAX /sizeof (PyObject * ));
2198
- PyObject * * base = tstate -> datastack_top ;
2199
- PyObject * * top = base + size ;
2200
- if ( top >= tstate -> datastack_limit ) {
2201
- base = push_chunk ( tstate , ( int ) size ) ;
2198
+ if ( _PyThreadState_HasStackSpace ( tstate , ( int ) size )) {
2199
+ _PyInterpreterFrame * res = ( _PyInterpreterFrame * ) tstate -> datastack_top ;
2200
+ tstate -> datastack_top += size ;
2201
+ return res ;
2202
2202
}
2203
- else {
2204
- tstate -> datastack_top = top ;
2205
- }
2206
- return (_PyInterpreterFrame * )base ;
2203
+ return (_PyInterpreterFrame * )push_chunk (tstate , (int )size );
2207
2204
}
2208
2205
2209
2206
void
You can’t perform that action at this time.
0 commit comments