Fix segfault calling `id_properties_ui("prop").update()`

Fix segfault when calling `some_id.id_properties_ui("propname").update()`,
i.e. call the `update()` function without any keyword arguments. In such
a case, Python passes `kwargs = NULL`, but `PyDict_Contains()` is not
`NULL`-safe.
This commit is contained in:
Sybren A. Stüvel 2022-02-14 10:58:21 +01:00
parent 1236d2aea8
commit e0fd31f083
1 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,12 @@
static bool args_contain_key(PyObject *kwargs, const char *name)
{
if (kwargs == NULL) {
/* When a function gets called without any kwargs, Python just passes NULL instead.
* PyDict_Contains() is not NULL-safe, though. */
return false;
}
PyObject *py_key = PyUnicode_FromString(name);
const bool result = PyDict_Contains(kwargs, py_key) == 1;
Py_DECREF(py_key);