Fixed a bug where the last character of a line would be lost when generating a list of string tokens.

This commit is contained in:
2022-01-05 22:51:56 +00:00
parent 0b46ac2f54
commit 8656ba7d0c
2 changed files with 31 additions and 5 deletions
+4 -4
View File
@@ -24,7 +24,7 @@ List* CreateList() {
}
int AddListItem(const char *value, List* list) {
if (list == NULL) return -1;
if (!list) return -1;
if (list->capacity < list->size + 1) {
void* ptr = realloc(list->root, sizeof(char*) * list->capacity * 2);
@@ -44,7 +44,7 @@ int AddListItem(const char *value, List* list) {
if (!item) {
fprintf(stderr, "Failed to malloc() new memory for '%s' (length: %lu bytes).\n", value, valueLength);
return -1;;
return -1;
}
strncpy(item, value, valueLength);
@@ -56,7 +56,7 @@ int AddListItem(const char *value, List* list) {
}
void PrintList(const List* list) {
if (list == NULL) return;
if (!list) return;
const List *current = list;
@@ -68,7 +68,7 @@ void PrintList(const List* list) {
}
void DestroyList(List* list) {
if (list == NULL) return;
if (!list) return;
for(int i = 0; i < list->size; i++) {
free(list->root[i]);