src/string_list.c

changeset 82
44b3332dfe03
parent 81
54515e5d60f5
--- a/src/string_list.c	Wed Apr 09 21:47:07 2025 +0200
+++ b/src/string_list.c	Thu Apr 10 21:29:56 2025 +0200
@@ -46,24 +46,18 @@
   }
 }
 
-/* Adds an item to the list, if a NULL-list is specified, the item will
- * be freed. This way a NULL-list can be used as garbage bin.
- */
 void add_string(string_list_t* list, char* item) {
-  if (list) {
-    if (list->count < list->capacity) {
-      list->items[list->count++] = item;
-      return;
-    }
-    size_t newCapacity = list->capacity * 2;
-    char** reallocated_list =
-      realloc(list->items, sizeof(char*) * newCapacity);
-    assert(reallocated_list != NULL);
-    list->capacity = newCapacity;
-    list->items = reallocated_list;
+  assert(list != NULL);
+  if (list->count < list->capacity) {
     list->items[list->count++] = item;
-  } else {
-    free(item);
+    return;
   }
+  size_t newCapacity = list->capacity * 2;
+  char** reallocated_list =
+    realloc(list->items, sizeof(char*) * newCapacity);
+  assert(reallocated_list != NULL);
+  list->capacity = newCapacity;
+  list->items = reallocated_list;
+  list->items[list->count++] = item;
 }
 

mercurial