Skip to content

Commit

Permalink
Don't use PyList_GetItemRef immediately after PyList_New
Browse files Browse the repository at this point in the history
  • Loading branch information
lysnikolaou authored and hugovk committed Jul 8, 2024
1 parent 87596bd commit 40e7f51
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {

Check warning on line 1214 in src/_imagingft.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

comparison of integer expressions of different signedness: ‘int’ and ‘FT_UInt’ {aka ‘unsigned int’} [-Wsign-compare]
list_names_filled[i] = 0;
}

if (list_names == NULL) {
FT_Done_MM_Var(library, master);
return NULL;
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 40e7f51

Please sign in to comment.