summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-09-06 15:45:43 (GMT)
committerGitHub <noreply@github.com>2022-09-06 15:45:43 (GMT)
commit222f10ca2d01c86fa2c53c2edd6884f117324297 (patch)
treec20d440c56d7dcb87c3c083dc737d0443c22b1b3 /Python
parentcd0ff9bd14d6a60e841d10f8415827db556ae622 (diff)
downloadcpython-222f10ca2d01c86fa2c53c2edd6884f117324297.zip
cpython-222f10ca2d01c86fa2c53c2edd6884f117324297.tar.gz
cpython-222f10ca2d01c86fa2c53c2edd6884f117324297.tar.bz2
GH-96569: Add two NULL checks to avoid undefined behavior. (GH-96585)
Diffstat (limited to 'Python')
-rw-r--r--Python/pystate.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index a11f162..1c96f4f 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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