]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
ctypes: fix CThunkObject_new()
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 27 Jul 2016 14:58:47 +0000 (16:58 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 27 Jul 2016 14:58:47 +0000 (16:58 +0200)
* Initialize restype and flags fields to fix a crash when Python runs on a
  read-only file system
* Use Py_ssize_t type rather than int for the "i" iterator variable
* Reorder assignements to be able to more easily check if all fields are
  initialized

Issue #11048. Initial patch written by Marcin Bachry.

Modules/_ctypes/callbacks.c

index b1e85ced8eaf2f272056e0dca6dbcf0c9511e695..ef1f0019db8847062375f8c1b56b8216f7875111 100644 (file)
@@ -385,7 +385,7 @@ static void closure_fcn(ffi_cif *cif,
 static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
 {
     CThunkObject *p;
-    int i;
+    Py_ssize_t i;
 
     p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs);
     if (p == NULL) {
@@ -393,11 +393,13 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
         return NULL;
     }
 
-    p->pcl_exec = NULL;
     p->pcl_write = NULL;
+    p->pcl_exec = NULL;
     memset(&p->cif, 0, sizeof(p->cif));
+    p->flags = 0;
     p->converters = NULL;
     p->callable = NULL;
+    p->restype = NULL;
     p->setfunc = NULL;
     p->ffi_restype = NULL;