# HG changeset patch # User ib # Date 1329135483 0 # Node ID e96ee4cac59fc7f328f629c9dd99d4fa4f215673 # Parent 97148652b0c658c3b5377ba32d09babb6da001cd Revise listSet(). Improve doxygen comments, replace for loop with index by while loop with pointer, fix bug with wrong allocation size, and check whether allocation succeeded. diff -r 97148652b0c6 -r e96ee4cac59f gui/util/list.c --- a/gui/util/list.c Mon Feb 13 10:22:02 2012 +0000 +++ b/gui/util/list.c Mon Feb 13 12:18:03 2012 +0000 @@ -190,22 +190,32 @@ } /** - * \brief This actually creates a new list containing only one element... + * @brief Set list to @a entry. + * + * @param list pointer to the char pointer list + * @param entry the new (and only) element of the list + * + * @note Actually, a new list will be created and the old list will be freed. */ void listSet(char ***list, const char *entry) { - int i; + if (*list) { + char **l = *list; - if (*list) { - for (i = 0; (*list)[i]; i++) - free((*list)[i]); + while (*l) { + free(*l); + l++; + } free(*list); } - *list = malloc(2 * sizeof(char **)); + *list = malloc(2 * sizeof(char *)); + + if (*list) { (*list)[0] = gstrdup(entry); (*list)[1] = NULL; + } } /**