From 2da49e3ca6357b65e31fb494b2edb0d22e73c62c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 13 Jun 2016 22:14:08 +0200 Subject: Don't crash when the key isn't found. --- src/core/settings.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core') 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) -- cgit v1.2.3