aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-03-17 01:20:56 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-03-17 01:20:56 -0400
commit5f1efa386ef5e2e7251fdd9bef8ad23a246f0099 (patch)
treea8a81fb2c5d7153f8f1f371fa6d1d0827036abc6 /src
parent54d2475f74f30be5e4ae476d9ac0df92f3e6ca12 (diff)
downloadspmc-5f1efa386ef5e2e7251fdd9bef8ad23a246f0099.tar.gz
strlist_set() accepts NULL value
Diffstat (limited to 'src')
-rw-r--r--src/strlist.c17
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));
}
/**