From 4be3a4a7ea20bf2edd8242feb29a26562c9de31e Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Thu, 30 Dec 2021 14:56:36 -0600 Subject: [PATCH] Changed the 'AddListItem' function to make a copy of the char array that its sent to make the caller's life a bit easier. --- src/list.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/list.c b/src/list.c index 76ce53a..f5c8256 100644 --- a/src/list.c +++ b/src/list.c @@ -1,4 +1,7 @@ #include "../includes/list.h" +#include +#include +#include List* CreateList() { List *new = malloc(sizeof(List)); @@ -16,7 +19,12 @@ int AddListItem(char *value, List* list) { list->capacity = list->capacity * 2; } - list->root[list->size] = value; + unsigned long valueLength = strlen(value) + 1; //Plus one for the null byte. + + char* item = malloc(valueLength); + strncpy(item, value, valueLength); + + list->root[list->size] = item; list->size++; return 0;