1. Carl Meyer
  2. cpython-site-tests

Commits

Thomas Heller  committed f373646

Assigning None to pointer type structure fields possible overwrote
wrong fields.

  • Participants
  • Parent commits 02598c5
  • Branches legacy-trunk

Comments (0)

Files changed (3)

File Lib/ctypes/test/test_structures.py

View file
         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()

File Misc/NEWS

View file
 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.
 

File Modules/_ctypes/_ctypes.c

View file
 			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 {