From 66e43caf9d83193575387429459e8ca09bf3db77 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 9 Nov 2015 20:03:38 +0100 Subject: [PATCH 1/3] CID 32303 Unchecked return value appeasing coverity --- src/magic.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; } From e14cc5025264be2b7df191de255d521dfeca05c0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 9 Nov 2015 20:05:55 +0100 Subject: [PATCH 2/3] CID 22522, 22520 Resource leak helping coverity scan to understand this code --- src/kernel/item.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kernel/item.c b/src/kernel/item.c index ca6c2f32d..1b312c655 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -187,6 +187,7 @@ resource_type *rt_get_or_create(const char *name) { else { rtype->_name = _strdup(name); rt_register(rtype); + return rt_find(name); } } return rtype; From edb862a8fcbd79089cc0044395b7f3fa4494b6d2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 9 Nov 2015 20:08:58 +0100 Subject: [PATCH 3/3] CID 22461 Division or modulo by zero partial fix github issue #326 also fewer calls to rmoney --- src/economy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/economy.c b/src/economy.c index c6e0d360a..9a9c5857a 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2898,11 +2898,12 @@ static void expandloot(region * r, request * lootorders) if (!norders) return; - for (i = 0; i != norders && rmoney(r) > TAXFRACTION * 2; i++) { + for (i = 0; i != norders && startmoney > TAXFRACTION * 2; i++) { change_money(oa[i].unit, TAXFRACTION); oa[i].unit->n += TAXFRACTION; /*Looting destroys double the money*/ - rsetmoney(r, rmoney(r) - TAXFRACTION * 2); + startmoney = startmoney - TAXFRACTION * 2; + rsetmoney(r, startmoney); looted = looted + TAXFRACTION * 2; } free(oa);