Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4574f23

Browse files
committed
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.
1 parent 493aa48 commit 4574f23

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Objects/bufferobject.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,14 @@ PyBuffer_New(size)
183183
{
184184
PyBufferObject * b;
185185

186+
if (size < 0) {
187+
PyErr_SetString(PyExc_ValueError,
188+
"size must be zero or positive");
189+
return NULL;
190+
}
186191
b = (PyBufferObject *)malloc(sizeof(*b) + size);
187192
if ( b == NULL )
188-
return NULL;
193+
return PyErr_NoMemory();
189194
b->ob_type = &PyBuffer_Type;
190195
_Py_NewReference((PyObject *)b);
191196

0 commit comments

Comments
 (0)