summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2016-06-13 22:14:08 +0200
committerLemonBoy <thatlemon@gmail.com>2016-06-13 22:14:08 +0200
commit2da49e3ca6357b65e31fb494b2edb0d22e73c62c (patch)
tree369f24dcaa311e6dff76376436048baabf7e4758 /src/core
parent862729d7a39be25aee3524a52e19f9735dec6e1f (diff)
downloadirssi-2da49e3ca6357b65e31fb494b2edb0d22e73c62c.zip
Don't crash when the key isn't found.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/settings.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index e6b5d16f..1242293d 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -153,7 +153,7 @@ int settings_get_choice(const char *key)
SETTINGS_REC *rec;
CONFIG_NODE *node;
char *str;
- int idx;
+ int index;
rec = settings_get(key, SETTING_TYPE_CHOICE);
if (rec == NULL) return -1;
@@ -164,8 +164,10 @@ int settings_get_choice(const char *key)
str = node == NULL ? rec->default_value.v_string :
config_node_get_str(node, key, rec->default_value.v_string);
- idx = strarray_find(rec->choices, str);
- return (idx < 0) ? rec->default_value.v_int : idx;
+ if (str == NULL || (index = strarray_find(rec->choices, str)) < 0)
+ return rec->default_value.v_int;
+
+ return index;
}
char *settings_get_print(SETTINGS_REC *rec)