From 77798c73c5ce16ef355436816514d703dfc84464 Mon Sep 17 00:00:00 2001 From: louie Date: Sun, 1 Aug 2021 13:36:48 -0700 Subject: Fixed invalid config path crash --- draw.c | 6 +++++- include/read_cfg.h | 2 +- read_cfg.c | 10 +++++++--- tasklist.md | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/draw.c b/draw.c index a66dc3b..daba27e 100644 --- a/draw.c +++ b/draw.c @@ -61,7 +61,11 @@ int main(int argc, char **argv){ if(!flags_set[0]) strcpy(cfg_path, find_config()); //find_config if not config flag was passed //Fill Groups - cfg_interp(cfg_path); //read the contents of the cfg file + //read the contents of the cfg file; print help message if invalid + if(!cfg_interp(cfg_path)){ + print_help(argv[0]); + return 0; + } //Remove Empty Groups from the Array clean_groups(); diff --git a/include/read_cfg.h b/include/read_cfg.h index 6b0c276..b6b996f 100644 --- a/include/read_cfg.h +++ b/include/read_cfg.h @@ -3,7 +3,7 @@ #define BUF_LEN 1024 -void cfg_interp(char *path); +bool cfg_interp(char *path); bool get_sort(); bool get_case_sensitivity(); void refer_to_doc(); diff --git a/read_cfg.c b/read_cfg.c index 61ddce1..77c4381 100644 --- a/read_cfg.c +++ b/read_cfg.c @@ -32,7 +32,8 @@ bool hr = false; //turn foldCase (insensitive case searching) on or off; On by default bool fold_case = true; -void cfg_interp(char *path){ +//return false if invalid path +bool cfg_interp(char *path){ FILE *fp; char buffer[BUF_LEN]; GROUP **g; @@ -43,7 +44,10 @@ void cfg_interp(char *path){ int j; fp = fopen(path, "r"); - assert(fp != NULL); + if(fp == NULL){ + printf("Error: Invalid Configuration Path \"%s\"\n", path); + return false; + } //build the options array char **options = malloc(sizeof(char *) * OPTION_CNT); @@ -87,7 +91,7 @@ void cfg_interp(char *path){ */ fclose(fp); - return; + return true; } bool get_sort(){ diff --git a/tasklist.md b/tasklist.md index c7e884d..14a7ea1 100644 --- a/tasklist.md +++ b/tasklist.md @@ -2,12 +2,12 @@ ## FIXME -- **If giving invalid config path for -c|--cfg\_path flag, program crashes** - - Should give a formal error message - **On Windows, running without alias option turned on in cfg causes instability** ### Completed +- If giving invalid config path for -c|--cfg\_path flag, program crashes + --- ## TODO -- cgit