Commit 326e1894 authored by Amaury Forgeot d'Arc's avatar Amaury Forgeot d'Arc

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

some functions like file.write().
parent caa745e7
...@@ -20,6 +20,10 @@ class StringBufferTestCase(unittest.TestCase): ...@@ -20,6 +20,10 @@ class StringBufferTestCase(unittest.TestCase):
self.assertEqual(b[::2], b"ac") self.assertEqual(b[::2], b"ac")
self.assertEqual(b[::5], b"a") self.assertEqual(b[::5], b"a")
def test_buffer_interface(self):
self.assertEqual(len(bytearray(create_string_buffer(0))), 0)
self.assertEqual(len(bytearray(create_string_buffer(1))), 1)
try: try:
c_wchar c_wchar
except NameError: except NameError:
......
...@@ -185,6 +185,9 @@ Library ...@@ -185,6 +185,9 @@ Library
Extension Modules 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 - Issue #10309: Define _GNU_SOURCE so that mremap() gets the proper
signature. Without this, architectures where sizeof void* != sizeof int are signature. Without this, architectures where sizeof void* != sizeof int are
broken. Patch given by Hallvard B Furuseth. broken. Patch given by Hallvard B Furuseth.
......
...@@ -2488,9 +2488,11 @@ static int PyCData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags) ...@@ -2488,9 +2488,11 @@ static int PyCData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
view->ndim = dict->ndim; view->ndim = dict->ndim;
view->shape = dict->shape; view->shape = dict->shape;
view->itemsize = self->b_size; view->itemsize = self->b_size;
if (view->itemsize) {
for (i = 0; i < view->ndim; ++i) { for (i = 0; i < view->ndim; ++i) {
view->itemsize /= dict->shape[i]; view->itemsize /= dict->shape[i];
} }
}
view->strides = NULL; view->strides = NULL;
view->suboffsets = NULL; view->suboffsets = NULL;
view->internal = NULL; view->internal = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment