Issue 33279: Py_BuildValue is causing crashes with the "L" and "K" format characters when upcasting sub 64-bit integer types (original) (raw)
New to both C and the CPython api so I'm not sure what compiler details matter but this is with VS14 and default compile parameters on windows 10 with 32bit Python.
The following function:
static PyObject *spam(PyObject *module) {
digit w = 9;
int x = 9;
long y = 9;
int32_t z = 9;
return Py_BuildValue("(HIK)(lll)(LLL)", w,w,w,x,y,z,x,y,z);
}
returns:
spam() ((9, 9, 38654705673), (9, 9, 9), (38654705673, 438244858264171835, 6133859984))
Above was the most I could fit in a single Py_BuildValue call without causing a crash (it instantly crashes if "O" or "N" fields are present). I believe this happens because the ints are being upcasted as pointers, which is undefined behavior.