From 8a5164806b06dd97b778e76ac029fd3ab0ee235b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Oct 2017 09:29:32 +0200 Subject: [PATCH] try fixing coverity complaints --- src/kernel/order.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/kernel/order.c b/src/kernel/order.c index 7cdb2961d..88f6313fa 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -156,7 +156,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si if (ord->id < 0) { skill_t sk = (skill_t)(100+ord->id); - assert(kwd == K_STUDY && sk != SK_MAGIC); + assert(kwd == K_STUDY && sk != SK_MAGIC && sk < MAXSKILLS); text = skillname(sk, lang); } else { od = load_data(ord->id); @@ -270,7 +270,7 @@ static int create_data(keyword_t kwd, const char *s, } /* TODO: between mkdata and release_data, this object is very * short-lived. */ - mkdata(&data, s ? strlen(s) : 0, s); + mkdata(&data, strlen(s), s); id = save_data(kwd, data); release_data(data); return id; @@ -351,7 +351,11 @@ order *create_order(keyword_t kwd, const struct locale * lang, zBuffer[0] = 0; } ord = (order *)malloc(sizeof(order)); - return create_order_i(ord, lang, kwd, zBuffer, false, false); + if (create_order_i(ord, lang, kwd, zBuffer, false, false) == NULL) { + free(ord); + return NULL; + } + return ord; } order *parse_order(const char *s, const struct locale * lang) @@ -383,7 +387,12 @@ order *parse_order(const char *s, const struct locale * lang) } if (kwd != NOKEYWORD) { order *ord = (order *)malloc(sizeof(order)); - return create_order_i(ord, lang, kwd, sptr, persistent, noerror); + if (create_order_i(ord, lang, kwd, sptr, persistent, noerror) + == NULL) { + free(ord); + return NULL; + } + return ord; } } return NULL; @@ -585,6 +594,7 @@ keyword_t init_order(const struct order *ord, const struct locale *lang) } if (ord->id < 0) { skill_t sk = (skill_t)(100 + ord->id); + assert(sk < MAXSKILLS); assert(lang); assert(kwd == K_STUDY); init_tokens_str(skillname(sk, lang));