lib: Fix baroque code in fp_discover_prints()

Use GPtrArray to simplify the implementation.

libfprint/fpi-data.c:777:13: warning: Access to field 'data' results in a dereference of a null pointer (loaded from variable 'elem')
                list[i] = elem->data;
                          ^~~~~~~~~~
This commit is contained in:
Bastien Nocera 2018-12-12 15:43:38 +01:00
parent 6725b22fd4
commit 52208a6606

View file

@ -734,9 +734,7 @@ API_EXPORTED struct fp_dscv_print **fp_discover_prints(void)
GError *err = NULL; GError *err = NULL;
GSList *tmplist = NULL; GSList *tmplist = NULL;
GSList *elem; GSList *elem;
unsigned int tmplist_len; GPtrArray *array;
struct fp_dscv_print **list;
unsigned int i;
if (!base_store) if (!base_store)
storage_setup(); storage_setup();
@ -771,15 +769,17 @@ API_EXPORTED struct fp_dscv_print **fp_discover_prints(void)
} }
g_dir_close(dir); g_dir_close(dir);
tmplist_len = g_slist_length(tmplist);
list = g_malloc(sizeof(*list) * (tmplist_len + 1)); if (tmplist == NULL)
elem = tmplist; return NULL;
for (i = 0; i < tmplist_len; i++, elem = g_slist_next(elem))
list[i] = elem->data; array = g_ptr_array_new();
list[tmplist_len] = NULL; /* NULL-terminate */ for (elem = tmplist; elem != NULL; elem = elem->next)
g_ptr_array_add(array, elem->data);
g_ptr_array_add(array, NULL);
g_slist_free(tmplist); g_slist_free(tmplist);
return list; return (struct fp_dscv_print **) g_ptr_array_free(array, FALSE);
} }
/** /**