From 027cfbd2cd212760424b2fa96bd6aeb755c53155 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 18 Jul 2022 13:55:06 +0200 Subject: correctly deal with multiple comments in a row, only allocate config values if possible, and free duplicates --- src/parser.c | 19 ++++++++++++++++--- src/ui.c | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/parser.c b/src/parser.c index 052acb4..d8ad576 100644 --- a/src/parser.c +++ b/src/parser.c @@ -73,7 +73,8 @@ void parse_config() assert((size_t)(tail - buf) <= file_size); ++tail; } - head = tail+1;; + + head = tail++; continue; } else if (*tail == '=') @@ -119,11 +120,23 @@ void parse_config() } else if (!strcmp(key, "project.script")) { - config.projects[config.project_count-1].script_path = strdup(value); + if (config.project_count > 0) + { + if (config.projects[config.project_count-1].script_path) + free(config.projects[config.project_count-1].script_path); + + config.projects[config.project_count-1].script_path = strdup(value); + } } else if (!strcmp(key, "project.description")) { - config.projects[config.project_count-1].description = strdup(value); + if (config.project_count > 0) + { + if (config.projects[config.project_count-1].description) + free(config.projects[config.project_count-1].description); + + config.projects[config.project_count-1].description = strdup(value); + } } key = NULL; diff --git a/src/ui.c b/src/ui.c index 25c810e..2740ef7 100644 --- a/src/ui.c +++ b/src/ui.c @@ -329,7 +329,7 @@ void print_project_list() "%s" "", project->name, project->name, - project->description, + project->description ? project->description : "", time, buildtime, class, status ); -- cgit v1.2.3