From: Fred Drake Date: Wed, 4 Aug 1999 13:08:19 +0000 (+0000) Subject: PyBuffer_New(): Raise ValueError if size is negative (the other X-Git-Tag: v1.6a1~1031 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4574f23115e2c0b35a2e1a4cac0aa7c855144639;p=thirdparty%2FPython%2Fcpython.git PyBuffer_New(): Raise ValueError if size is negative (the other constructors didn't miss this). Raise MemoryError if malloc() fails, instead of just returning NULL. --- diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c index 017ae64416bb..05b1f11406d4 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);