]> sigrok.org Git - libserialport.git/commitdiff
Fix list append.
authorMartin Ling <redacted>
Wed, 8 May 2013 01:55:43 +0000 (02:55 +0100)
committerUwe Hermann <redacted>
Thu, 14 Nov 2013 23:42:37 +0000 (00:42 +0100)
serialport.c

index 60a1a751ee096304bc4068babbe87db9816d0da3..6fc52688c6d4871bacf07cf3361f4843eae9d3b6 100644 (file)
@@ -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);