]> granicus.if.org Git - python/commitdiff
Assigning None to pointer type structure fields possible overwrote
authorThomas Heller <theller@ctypes.org>
Mon, 10 Jul 2006 11:11:10 +0000 (11:11 +0000)
committerThomas Heller <theller@ctypes.org>
Mon, 10 Jul 2006 11:11:10 +0000 (11:11 +0000)
wrong fields.

Lib/ctypes/test/test_structures.py
Misc/NEWS
Modules/_ctypes/_ctypes.c

index bb56a6185032671cdf93d16fdeb130a659663a14..8a4531db936dc3d43ad8a9111e2a258bdb18d586 100644 (file)
@@ -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()
index 157c1653f5da7009172d1ba1c517039b064eafc5..a0266c4ec5cd93bd3c98b45844446bf5a6835073 100644 (file)
--- 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.
 
index f786ead4bae691b7627788529faff655a1da1240..b3329321efae241a1cc46a482366c4592304bdbf 100644 (file)
@@ -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 {