From 5f1efa386ef5e2e7251fdd9bef8ad23a246f0099 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 17 Mar 2020 01:20:56 -0400 Subject: strlist_set() accepts NULL value --- src/strlist.c | 17 +++++++++++------ 1 file 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)); } /** -- cgit