diff options
-rw-r--r-- | Objects/bufferobject.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c index 017ae64..05b1f11 100644 --- a/Objects/bufferobject.c +++ b/Objects/bufferobject.c @@ -183,9 +183,14 @@ PyBuffer_New(size) { PyBufferObject * b; + if (size < 0) { + PyErr_SetString(PyExc_ValueError, + "size must be zero or positive"); + return NULL; + } b = (PyBufferObject *)malloc(sizeof(*b) + size); if ( b == NULL ) - return NULL; + return PyErr_NoMemory(); b->ob_type = &PyBuffer_Type; _Py_NewReference((PyObject *)b); |