diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-06-13 13:03:07 -0400 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-06-13 13:03:07 -0400 | 
| commit | eb04d1bf3e50bf6121e48f0e08aac0d95fd34c81 (patch) | |
| tree | fa53b3abb6ff66cf2f525effb65e76f241de8765 /src | |
| parent | 9f235ec8ee1d9a08519707aed4b698867889b7fa (diff) | |
| download | ohmycal-eb04d1bf3e50bf6121e48f0e08aac0d95fd34c81.tar.gz | |
Fix strlist_remove function
Diffstat (limited to 'src')
| -rw-r--r-- | src/strlist.c | 18 | 
1 files changed, 6 insertions, 12 deletions
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--;      }  }  | 
