From 63f91c5f67f15af3b47f37018b72c19d5f9df306 Mon Sep 17 00:00:00 2001 From: Lexi Quinn Date: Thu, 27 Jan 2022 05:18:21 +1100 Subject: [PATCH] Fixed that pesky malloc bug --- src/timer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/timer.c b/src/timer.c index 9350d6f..957209e 100644 --- a/src/timer.c +++ b/src/timer.c @@ -449,7 +449,7 @@ void loadConfig() strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps"); mkdir(path, 0777); strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps/default"); - configpath = malloc(strlen(path)); + configpath = malloc(strlen(path) + 1); strcpy(configpath, path); long length; @@ -575,14 +575,14 @@ void loadFile() if (game) { cJSON *title = cJSON_GetItem(game, "name"); if (cJSON_IsString(title) && (title->valuestring != NULL)) { - gameTitle = malloc(strlen(title->valuestring)); + gameTitle = malloc(strlen(title->valuestring) + 1); strcpy(gameTitle, title->valuestring); } } if (cate) { cJSON *title = cJSON_GetItem(cate, "name"); if (cJSON_IsString(title) && (title->valuestring != NULL)) { - categoryTitle = malloc(strlen(title->valuestring)); + categoryTitle = malloc(strlen(title->valuestring) + 1); strcpy(categoryTitle, title->valuestring); } } @@ -603,7 +603,7 @@ void loadFile() cJSON_ArrayForEach(iterator, segs) { segname = cJSON_GetItem(iterator, "name"); if (cJSON_IsString(segname) && (segname->valuestring != NULL)) { - segments[it].name = malloc(strlen(segname->valuestring)); + segments[it].name = malloc(strlen(segname->valuestring) + 1); strcpy(segments[it].name, segname->valuestring); } it++;