summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2006-07-10 11:11:10 +0000
committerThomas Heller <theller@ctypes.org>2006-07-10 11:11:10 +0000
commit4ccfaf7c29e20b2c913eb8e0472810e6a574b3b5 (patch)
tree6423494f53998430e5db042cc53359b4f74e780f
parent4e55f28746611e87f01a0572ca7eb2c026355d16 (diff)
downloadcpython-4ccfaf7c29e20b2c913eb8e0472810e6a574b3b5.tar.gz
Assigning None to pointer type structure fields possible overwrote
wrong fields.
-rw-r--r--Lib/ctypes/test/test_structures.py10
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_ctypes/_ctypes.c2
3 files changed, 14 insertions, 1 deletions
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index bb56a61850..8a4531db93 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -371,5 +371,15 @@ class PointerMemberTestCase(unittest.TestCase):
items = [s.array[i] for i in range(3)]
self.failUnlessEqual(items, [1, 2, 3])
+ def test_none_to_pointer_fields(self):
+ class S(Structure):
+ _fields_ = [("x", c_int),
+ ("p", POINTER(c_int))]
+
+ s = S()
+ s.x = 12345678
+ s.p = None
+ self.failUnlessEqual(s.x, 12345678)
+
if __name__ == '__main__':
unittest.main()
diff --git a/Misc/NEWS b/Misc/NEWS
index 157c1653f5..a0266c4ec5 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -39,6 +39,9 @@ Core and builtins
Library
-------
+- Assigning None to pointer type fields in ctypes structures possible
+ overwrote the wrong fields, this is fixed now.
+
- Fixed a segfault in _ctypes when ctypes.wintypes were imported
on non-Windows platforms.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index f786ead4ba..b3329321ef 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2187,7 +2187,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
Py_DECREF(ob);
return result;
} else if (value == Py_None && PointerTypeObject_Check(type)) {
- *(void **)dst->b_ptr = NULL;
+ *(void **)ptr = NULL;
Py_INCREF(Py_None);
return Py_None;
} else {