From: Martin Ling Date: Wed, 8 May 2013 01:55:43 +0000 (+0100) Subject: Fix list append. X-Git-Tag: libserialport-0.1.0~163 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=db2794cea96bcf2f953bc5da5071043e2dd665ce;p=libserialport.git Fix list append. --- diff --git a/serialport.c b/serialport.c index 60a1a75..6fc5268 100644 --- a/serialport.c +++ b/serialport.c @@ -56,12 +56,13 @@ static char **sp_list_append(char **list, void *data, size_t len) void *tmp; unsigned int count; for (count = 0; list[count]; count++); - if (!(tmp = realloc(list, sizeof(char *) * (++count + 1)))) + if (!(tmp = realloc(list, sizeof(char *) * (count + 2)))) goto fail; list = tmp; if (!(list[count] = malloc(len))) goto fail; memcpy(list[count], data, len); + list[count + 1] = NULL; return list; fail: sp_free_port_list(list);