]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyBuffer_New(): Raise ValueError if size is negative (the other
authorFred Drake <fdrake@acm.org>
Wed, 4 Aug 1999 13:08:19 +0000 (13:08 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 4 Aug 1999 13:08:19 +0000 (13:08 +0000)
 constructors didn't miss this).

 Raise MemoryError if malloc() fails, instead of just
 returning NULL.

Objects/bufferobject.c

index 017ae64416bb970b011897cd206549f87c158410..05b1f11406d4f2dc0391a5c45e334dadaf5fb070 100644 (file)
@@ -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);