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:
+9
-1
@@ -1,4 +1,7 @@
|
|||||||
#include "../includes/list.h"
|
#include "../includes/list.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
List* CreateList() {
|
List* CreateList() {
|
||||||
List *new = malloc(sizeof(List));
|
List *new = malloc(sizeof(List));
|
||||||
@@ -16,7 +19,12 @@ int AddListItem(char *value, List* list) {
|
|||||||
list->capacity = list->capacity * 2;
|
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++;
|
list->size++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user