[Python-checkins] cpython (2.7): Issue #9651: Fix a crash when ctypes.create_string_buffer(0) was passed to
amaury.forgeotdarc
python-checkins at python.org
Tue Aug 30 22:07:47 CEST 2011
http://hg.python.org/cpython/rev/4aa00f465b4f
changeset: 72142:4aa00f465b4f
branch: 2.7
parent: 72138:4c6b1b2d481a
user: Amaury Forgeot d'Arc <amauryfa at gmail.com>
date: Tue Aug 30 21:04:35 2011 +0200
summary:
Issue #9651: Fix a crash when ctypes.create_string_buffer(0) was passed to
some functions like file.write().
files:
Lib/ctypes/test/test_buffers.py | 4 ++++
Misc/NEWS | 3 +++
Modules/_ctypes/_ctypes.c | 6 ++++--
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/Lib/ctypes/test/test_buffers.py b/Lib/ctypes/test/test_buffers.py
--- a/Lib/ctypes/test/test_buffers.py
+++ b/Lib/ctypes/test/test_buffers.py
@@ -20,6 +20,10 @@
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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -180,6 +180,9 @@
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.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2576,8 +2576,10 @@
view->ndim = dict->ndim;
view->shape = dict->shape;
view->itemsize = self->b_size;
- for (i = 0; i < view->ndim; ++i) {
- view->itemsize /= dict->shape[i];
+ if (view->itemsize) {
+ for (i = 0; i < view->ndim; ++i) {
+ view->itemsize /= dict->shape[i];
+ }
}
view->strides = NULL;
view->suboffsets = NULL;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list