From 40e7f511b33204a23faa0f26140dd7b74c13be97 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Fri, 5 Jul 2024 16:30:48 +0200 Subject: [PATCH] Don't use PyList_GetItemRef immediately after PyList_New --- src/_imagingft.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/_imagingft.c b/src/_imagingft.c index 468f1688487..ddcf28f97eb 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -1205,6 +1205,16 @@ font_getvarnames(FontObject *self) { num_namedstyles = master->num_namedstyles; list_names = PyList_New(num_namedstyles); + + int *list_names_filled = PyMem_Malloc(num_namedstyles * sizeof(int)); + if (list_names_filled == NULL) { + return PyErr_NoMemory(); + } + + for (int i = 0; i < num_namedstyles; i++) { + list_names_filled[i] = 0; + } + if (list_names == NULL) { FT_Done_MM_Var(library, master); return NULL; @@ -1220,13 +1230,14 @@ font_getvarnames(FontObject *self) { } for (j = 0; j < num_namedstyles; j++) { - if (PyList_GetItemRef(list_names, j) != NULL) { + if (list_names_filled[j]) { continue; } if (master->namedstyle[j].strid == name.name_id) { list_name = Py_BuildValue("y#", name.string, name.string_len); PyList_SetItem(list_names, j, list_name); + list_names_filled[j] = 1; break; } }