Fixed that pesky malloc bug

This commit is contained in:
Lexi Quinn 2022-01-27 05:18:21 +11:00
parent 5e54972f6d
commit 63f91c5f67

View File

@ -449,7 +449,7 @@ void loadConfig()
strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps"); strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps");
mkdir(path, 0777); mkdir(path, 0777);
strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps/default"); strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps/default");
configpath = malloc(strlen(path)); configpath = malloc(strlen(path) + 1);
strcpy(configpath, path); strcpy(configpath, path);
long length; long length;
@ -575,14 +575,14 @@ void loadFile()
if (game) { if (game) {
cJSON *title = cJSON_GetItem(game, "name"); cJSON *title = cJSON_GetItem(game, "name");
if (cJSON_IsString(title) && (title->valuestring != NULL)) { if (cJSON_IsString(title) && (title->valuestring != NULL)) {
gameTitle = malloc(strlen(title->valuestring)); gameTitle = malloc(strlen(title->valuestring) + 1);
strcpy(gameTitle, title->valuestring); strcpy(gameTitle, title->valuestring);
} }
} }
if (cate) { if (cate) {
cJSON *title = cJSON_GetItem(cate, "name"); cJSON *title = cJSON_GetItem(cate, "name");
if (cJSON_IsString(title) && (title->valuestring != NULL)) { if (cJSON_IsString(title) && (title->valuestring != NULL)) {
categoryTitle = malloc(strlen(title->valuestring)); categoryTitle = malloc(strlen(title->valuestring) + 1);
strcpy(categoryTitle, title->valuestring); strcpy(categoryTitle, title->valuestring);
} }
} }
@ -603,7 +603,7 @@ void loadFile()
cJSON_ArrayForEach(iterator, segs) { cJSON_ArrayForEach(iterator, segs) {
segname = cJSON_GetItem(iterator, "name"); segname = cJSON_GetItem(iterator, "name");
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) { 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); strcpy(segments[it].name, segname->valuestring);
} }
it++; it++;