summaryrefslogtreecommitdiff
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-08 22:17:52 +0200
committerVictor Stinner <victor.stinner@gmail.com>2013-07-08 22:17:52 +0200
commit5d1866c78a4caf9825a0ce90863c19f65279da86 (patch)
tree6a849631579d60c3b9ea86db6e2b9f768b69e107 /Modules/gcmodule.c
parentc1eb26cd2fc9bfe65063a5e73ac2051424b10f82 (diff)
downloadcpython-git-5d1866c78a4caf9825a0ce90863c19f65279da86.tar.gz
Issue #18408: PyObject_GC_NewVar() now raises SystemError exception if nitems
is negative
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 51c80b236e..d96d2c7b68 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1689,8 +1689,15 @@ _PyObject_GC_New(PyTypeObject *tp)
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;