don't segfault when no dunstrc is found

This commit is contained in:
Sascha Kruse 2013-02-27 00:02:14 +01:00
parent de4db5e559
commit 37242bc30a
2 changed files with 10 additions and 8 deletions

View File

@ -108,9 +108,6 @@ char *ini_get_string(char *section, char *key, const char *def)
if (value) if (value)
return g_strdup(value); return g_strdup(value);
if (def == NULL)
return NULL;
else
return def ? g_strdup(def) : NULL; return def ? g_strdup(def) : NULL;
} }
@ -197,6 +194,9 @@ int load_ini_file(FILE * fp)
{ {
char line[BUFSIZ]; char line[BUFSIZ];
if (!fp)
return 1;
int line_num = 0; int line_num = 0;
char *current_section = NULL; char *current_section = NULL;
while (fgets(line, sizeof(line), fp) != NULL) { while (fgets(line, sizeof(line), fp) != NULL) {
@ -383,6 +383,7 @@ char *option_get_string(char *ini_section, char *ini_key, char *cmdline_key,
val = cmdline_get_string(cmdline_key, NULL, description); val = cmdline_get_string(cmdline_key, NULL, description);
} }
if (val) { if (val) {
return val; return val;
} else { } else {

View File

@ -49,7 +49,6 @@ void load_settings(char *cmdline_config_path)
if (config_file == NULL) { if (config_file == NULL) {
puts("no dunstrc found -> skipping\n"); puts("no dunstrc found -> skipping\n");
xdgWipeHandle(&xdg); xdgWipeHandle(&xdg);
return;
} }
} }
@ -300,9 +299,11 @@ void load_settings(char *cmdline_config_path)
} }
#ifndef STATIC_CONFIG #ifndef STATIC_CONFIG
if (config_file) {
fclose(config_file); fclose(config_file);
free_ini(); free_ini();
xdgWipeHandle(&xdg); xdgWipeHandle(&xdg);
}
#endif #endif
} }
/* vim: set ts=8 sw=8 tw=0: */ /* vim: set ts=8 sw=8 tw=0: */