mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Issue #12764: Fix a crash in ctypes when the name of a Structure field is not
a string.
This commit is contained in:
parent
172f374a63
commit
02dd539dbb
3 changed files with 26 additions and 2 deletions
|
|
@ -482,8 +482,21 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
|
|||
char *fieldfmt = dict->format ? dict->format : "B";
|
||||
char *fieldname = _PyUnicode_AsString(name);
|
||||
char *ptr;
|
||||
Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
|
||||
char *buf = alloca(len + 2 + 1);
|
||||
Py_ssize_t len;
|
||||
char *buf;
|
||||
|
||||
if (fieldname == NULL)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"structure field name must be string not %s",
|
||||
name->ob_type->tp_name);
|
||||
|
||||
Py_DECREF(pair);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = strlen(fieldname) + strlen(fieldfmt);
|
||||
buf = alloca(len + 2 + 1);
|
||||
|
||||
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue