Changed the 'AddListItem' function to make a copy of the char array that its sent to make the caller's life a bit easier.

This commit is contained in:
2021-12-30 14:56:36 -06:00
parent 168d8e1548
commit 4be3a4a7ea
+9 -1
View File
@@ -1,4 +1,7 @@
#include "../includes/list.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;