mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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:
parent
493aa4809b
commit
4574f23115
1 changed files with 6 additions and 1 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue