Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);
void
_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);


static inline bool
_PyThreadState_HasStackSpace(PyThreadState *tstate, int size)
{
Comment thread
markshannon marked this conversation as resolved.
return tstate->datastack_top + size < tstate->datastack_limit;
return tstate->datastack_top != NULL &&
size < tstate->datastack_limit - tstate->datastack_top;
}

extern _PyInterpreterFrame *
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove two cases of undefined behavoir, by adding NULL checks.
13 changes: 5 additions & 8 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2195,15 +2195,12 @@ _PyInterpreterFrame *
_PyThreadState_PushFrame(PyThreadState *tstate, size_t size)
{
assert(size < INT_MAX/sizeof(PyObject *));
PyObject **base = tstate->datastack_top;
PyObject **top = base + size;
if (top >= tstate->datastack_limit) {
base = push_chunk(tstate, (int)size);
if (_PyThreadState_HasStackSpace(tstate, (int)size)) {
_PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
tstate->datastack_top += size;
Comment thread
markshannon marked this conversation as resolved.
return res;
}
else {
tstate->datastack_top = top;
}
return (_PyInterpreterFrame *)base;
return (_PyInterpreterFrame *)push_chunk(tstate, (int)size);
}

void
Expand Down