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.
This commit is contained in:
Fred Drake 1999-08-04 13:08:19 +00:00
parent 493aa4809b
commit 4574f23115

View 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);