Issue #9651: Fix a crash when ctypes.create_string_buffer(0) was passed to

some functions like file.write().
This commit is contained in:
Amaury Forgeot d'Arc 2011-08-30 21:04:35 +02:00
parent 9bfc16a99e
commit 3d7f236329
3 changed files with 11 additions and 2 deletions

View File

@ -20,6 +20,10 @@ class StringBufferTestCase(unittest.TestCase):
self.assertEqual(b[::2], "ac")
self.assertEqual(b[::5], "a")
def test_buffer_interface(self):
self.assertEqual(len(bytearray(create_string_buffer(0))), 0)
self.assertEqual(len(bytearray(create_string_buffer(1))), 1)
def test_string_conversion(self):
b = create_string_buffer(u"abc")
self.assertEqual(len(b), 4) # trailing nul char

View File

@ -180,6 +180,9 @@ Library
Extension Modules
-----------------
- Issue #9651: Fix a crash when ctypes.create_string_buffer(0) was passed to
some functions like file.write().
- Issue #10309: Define _GNU_SOURCE so that mremap() gets the proper
signature. Without this, architectures where sizeof void* != sizeof int are
broken. Patch given by Hallvard B Furuseth.

View File

@ -2576,9 +2576,11 @@ static int PyCData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
view->ndim = dict->ndim;
view->shape = dict->shape;
view->itemsize = self->b_size;
if (view->itemsize) {
for (i = 0; i < view->ndim; ++i) {
view->itemsize /= dict->shape[i];
}
}
view->strides = NULL;
view->suboffsets = NULL;
view->internal = NULL;