From eb04d1bf3e50bf6121e48f0e08aac0d95fd34c81 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 13 Jun 2024 13:03:07 -0400 Subject: Fix strlist_remove function --- src/strlist.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/strlist.c b/src/strlist.c index 0cad270..bdacb5a 100644 --- a/src/strlist.c +++ b/src/strlist.c @@ -215,19 +215,13 @@ void strlist_remove(struct StrList *pStrList, size_t index) { if (count == 0) { return; } - - for (size_t i = index; i < count; i++) { - char *next = pStrList->data[i + 1]; - if (next == NULL) { - break; + if (pStrList->data[index] != NULL) { + for (size_t i = index; i < count; i++) { + pStrList->data[i] = pStrList->data[i + 1]; + } + if (pStrList->num_inuse) { + pStrList->num_inuse--; } - pStrList->data[i] = next; - count = strlist_count(pStrList); - pStrList->data[count - 1] = NULL; - } - if (pStrList->num_inuse) { - guard_free(pStrList->data[pStrList->num_inuse]); - pStrList->num_inuse--; } } -- cgit