Commit 5d1866c7 authored by Victor Stinner's avatar Victor Stinner

Issue #18408: PyObject_GC_NewVar() now raises SystemError exception if nitems

is negative
parent c1eb26cd
...@@ -1689,8 +1689,15 @@ _PyObject_GC_New(PyTypeObject *tp) ...@@ -1689,8 +1689,15 @@ _PyObject_GC_New(PyTypeObject *tp)
PyVarObject * PyVarObject *
_PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems) _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{ {
const size_t size = _PyObject_VAR_SIZE(tp, nitems); size_t size;
PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size); PyVarObject *op;
if (nitems < 0) {
PyErr_BadInternalCall();
return NULL;
}
size = _PyObject_VAR_SIZE(tp, nitems);
op = (PyVarObject *) _PyObject_GC_Malloc(size);
if (op != NULL) if (op != NULL)
op = PyObject_INIT_VAR(op, tp, nitems); op = PyObject_INIT_VAR(op, tp, nitems);
return op; return op;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment