GH-96569: Add two NULL checks to avoid undefined behavior. (GH-96585)

This commit is contained in:
Mark Shannon 2022-09-06 16:45:43 +01:00 committed by GitHub
parent cd0ff9bd14
commit 222f10ca2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View file

@ -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;
return res;
}
else {
tstate->datastack_top = top;
}
return (_PyInterpreterFrame *)base;
return (_PyInterpreterFrame *)push_chunk(tstate, (int)size);
}
void