mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Assigning None to pointer type structure fields possible overwrote
wrong fields.
This commit is contained in:
parent
7b1da513fd
commit
7644262aa5
3 changed files with 14 additions and 1 deletions
|
@ -371,5 +371,15 @@ class PointerMemberTestCase(unittest.TestCase):
|
||||||
items = [s.array[i] for i in range(3)]
|
items = [s.array[i] for i in range(3)]
|
||||||
self.failUnlessEqual(items, [1, 2, 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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -39,6 +39,9 @@ Core and builtins
|
||||||
Library
|
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
|
- Fixed a segfault in _ctypes when ctypes.wintypes were imported
|
||||||
on non-Windows platforms.
|
on non-Windows platforms.
|
||||||
|
|
||||||
|
|
|
@ -2187,7 +2187,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
|
||||||
Py_DECREF(ob);
|
Py_DECREF(ob);
|
||||||
return result;
|
return result;
|
||||||
} else if (value == Py_None && PointerTypeObject_Check(type)) {
|
} else if (value == Py_None && PointerTypeObject_Check(type)) {
|
||||||
*(void **)dst->b_ptr = NULL;
|
*(void **)ptr = NULL;
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue