mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
[3.11] GH-96569: Avoid undefined behavior (#96616)
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
This commit is contained in:
parent
3d6e6beb0d
commit
e72f469e85
3 changed files with 25 additions and 16 deletions
|
@ -2178,16 +2178,16 @@ push_chunk(PyThreadState *tstate, int size)
|
|||
_PyInterpreterFrame *
|
||||
_PyThreadState_BumpFramePointerSlow(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, size)) {
|
||||
_PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
|
||||
tstate->datastack_top += size;
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
tstate->datastack_top = top;
|
||||
if (size > INT_MAX/2) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
return (_PyInterpreterFrame *)base;
|
||||
return (_PyInterpreterFrame *)push_chunk(tstate, (int)size);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue