From 34d50ef2b59d12910bf26520c55283fd13bc31a1 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 9 Nov 2015 23:04:35 +1300 Subject: Switched config file name from allocated pointers to set buffers --- config_file.c | 22 ++++++++++++---------- config_file.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/config_file.c b/config_file.c index 1fc9899..5abe1b3 100644 --- a/config_file.c +++ b/config_file.c @@ -23,11 +23,13 @@ #include #include #include +#include void config_init() { struct config_file config; - char *xdg_config_home; + char *xdg_config_home = NULL; + char config_home[1024]; FILE* fd = NULL; config.key_file = NULL; @@ -37,18 +39,19 @@ void config_init() * */ xdg_config_home = getenv("XDG_CONFIG_HOME"); + + /* FIXME: unchecked return values from snprintf */ if (xdg_config_home == NULL) - xdg_config_home = g_strconcat(getenv("HOME"), "/.config", NULL); + snprintf(config_home, sizeof(config_home), "%s/.config", getenv("HOME")); + else + strncpy(config_home, xdg_config_home, sizeof(config_home)); - config.file_name = g_strconcat(xdg_config_home, "/paramano.conf", NULL); + snprintf(config.file_name, sizeof(config.file_name), "%s/paramano.conf", config_home); if( (fd = fopen(config.file_name, "r")) ) - { fclose(fd); - } else { - /* no (readable) user-specific config file, fall back */ - config.file_name = g_strconcat(PARAMANO_CONF, NULL); - } + else + strncpy(config.file_name, PARAMANO_CONF, sizeof(config.file_name)); /* fallback to system-wide */ if(!config_open(&config)) { @@ -69,10 +72,9 @@ void config_init() DEFAULT_SHOW_BATTERY = ( temp[0] == '1' ); if ((temp = config_get_key(&config, "extra", "theme"))) - snprintf(DEFAULT_THEME, sizeof(DEFAULT_THEME), "%s", temp); + strncpy(DEFAULT_THEME, temp, sizeof(DEFAULT_THEME)); config_close(&config); - g_free(config.file_name); } gboolean config_open(struct config_file* config_file) diff --git a/config_file.h b/config_file.h index 7c9f8ab..ac23481 100644 --- a/config_file.h +++ b/config_file.h @@ -22,7 +22,7 @@ struct config_file { GKeyFile* key_file; - gchar* file_name; + char file_name[4096]; }; void config_init(); -- cgit v1.1