diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-17 01:20:56 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-17 01:20:56 -0400 |
commit | 5f1efa386ef5e2e7251fdd9bef8ad23a246f0099 (patch) | |
tree | a8a81fb2c5d7153f8f1f371fa6d1d0827036abc6 /src | |
parent | 54d2475f74f30be5e4ae476d9ac0df92f3e6ca12 (diff) | |
download | spmc-5f1efa386ef5e2e7251fdd9bef8ad23a246f0099.tar.gz |
strlist_set() accepts NULL value
Diffstat (limited to 'src')
-rw-r--r-- | src/strlist.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/strlist.c b/src/strlist.c index ed00fb1..1cab324 100644 --- a/src/strlist.c +++ b/src/strlist.c @@ -155,13 +155,18 @@ void strlist_set(StrList *pStrList, size_t index, char *value) { if ((item = strlist_item(pStrList, index)) == NULL) { return; } - if ((tmp = realloc(pStrList->data[index], strlen(value) + 1)) == NULL) { - perror("realloc strlist_set replacement value"); - return; + if (value == NULL) { + pStrList->data[index] = NULL; + } else { + if ((tmp = realloc(pStrList->data[index], strlen(value) + 1)) == NULL) { + perror("realloc strlist_set replacement value"); + return; + } + + pStrList->data[index] = tmp; + memset(pStrList->data[index], '\0', strlen(value) + 1); + strncpy(pStrList->data[index], value, strlen(value)); } - pStrList->data[index] = tmp; - memset(pStrList->data[index], '\0', strlen(value) + 1); - strncpy(pStrList->data[index], value, strlen(value)); } /** |