(original) (raw)
changeset: 84508:111c2a070f28 user: Victor Stinner victor.stinner@gmail.com date: Mon Jul 08 22:17:52 2013 +0200 files: Modules/gcmodule.c description: Issue #18408: PyObject_GC_NewVar() now raises SystemError exception if nitems is negative diff -r 781be7ad1074 -r 111c2a070f28 Modules/gcmodule.c --- a/Modules/gcmodule.c Mon Jul 08 22:15:05 2013 +0200 +++ b/Modules/gcmodule.c Mon Jul 08 22:17:52 2013 +0200 @@ -1689,8 +1689,15 @@ PyVarObject * _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems) { - const size_t size = _PyObject_VAR_SIZE(tp, nitems); - PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size); + size_t 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) op = PyObject_INIT_VAR(op, tp, nitems); return op; /victor.stinner@gmail.com