Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e33797b

Browse files
committed
ctypes: fix CThunkObject_new()
* 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.
1 parent 25539b0 commit e33797b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Modules/_ctypes/callbacks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,19 +305,21 @@ static void closure_fcn(ffi_cif *cif,
305305
static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
306306
{
307307
CThunkObject *p;
308-
int i;
308+
Py_ssize_t i;
309309

310310
p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs);
311311
if (p == NULL) {
312312
PyErr_NoMemory();
313313
return NULL;
314314
}
315315

316-
p->pcl_exec = NULL;
317316
p->pcl_write = NULL;
317+
p->pcl_exec = NULL;
318318
memset(&p->cif, 0, sizeof(p->cif));
319+
p->flags = 0;
319320
p->converters = NULL;
320321
p->callable = NULL;
322+
p->restype = NULL;
321323
p->setfunc = NULL;
322324
p->ffi_restype = NULL;
323325

0 commit comments

Comments
 (0)