diff --git a/src/magic.c b/src/magic.c index ce69df78f..1873bb041 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2978,7 +2978,7 @@ spellbook * get_spellbook(const char * name) spellbook * result; void * match; - if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0)) { + if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0) > 0) { cb_get_kv(match, &result, sizeof(result)); } else { @@ -2990,8 +2990,10 @@ spellbook * get_spellbook(const char * name) log_error("cb_insert failed although cb_find returned nothing for spellbook=%s", name); assert(!"should not happen"); } - cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0); - cb_get_kv(match, &result, sizeof(result)); + result = 0; + if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0) > 0) { + cb_get_kv(match, &result, sizeof(result)); + } } return result; }