[MPlayer-cvslog] r34710 - trunk/gui/util/list.c

ib subversion at mplayerhq.hu
Mon Feb 13 13:18:03 CET 2012


Author: ib
Date: Mon Feb 13 13:18:03 2012
New Revision: 34710

Log:
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.

Modified:
   trunk/gui/util/list.c

Modified: trunk/gui/util/list.c
==============================================================================
--- trunk/gui/util/list.c	Mon Feb 13 11:22:02 2012	(r34709)
+++ trunk/gui/util/list.c	Mon Feb 13 13:18:03 2012	(r34710)
@@ -190,22 +190,32 @@ void *listMgr(int cmd, void *data)
 }
 
 /**
- * \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) {
-        for (i = 0; (*list)[i]; i++)
-            free((*list)[i]);
+        char **l = *list;
+
+        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;
+    }
 }
 
 /**


More information about the MPlayer-cvslog mailing list