try fixing coverity complaints

This commit is contained in:
Enno Rehling 2017-10-10 09:29:32 +02:00
parent fc80f2bd8c
commit 0a0806a181
1 changed files with 14 additions and 4 deletions

View File

@ -156,7 +156,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
if (ord->id < 0) { if (ord->id < 0) {
skill_t sk = (skill_t)(100+ord->id); 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); text = skillname(sk, lang);
} else { } else {
od = load_data(ord->id); 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 /* TODO: between mkdata and release_data, this object is very
* short-lived. */ * short-lived. */
mkdata(&data, s ? strlen(s) : 0, s); mkdata(&data, strlen(s), s);
id = save_data(kwd, data); id = save_data(kwd, data);
release_data(data); release_data(data);
return id; return id;
@ -351,7 +351,11 @@ order *create_order(keyword_t kwd, const struct locale * lang,
zBuffer[0] = 0; zBuffer[0] = 0;
} }
ord = (order *)malloc(sizeof(order)); 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) 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) { if (kwd != NOKEYWORD) {
order *ord = (order *)malloc(sizeof(order)); 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; return NULL;
@ -585,6 +594,7 @@ keyword_t init_order(const struct order *ord, const struct locale *lang)
} }
if (ord->id < 0) { if (ord->id < 0) {
skill_t sk = (skill_t)(100 + ord->id); skill_t sk = (skill_t)(100 + ord->id);
assert(sk < MAXSKILLS);
assert(lang); assert(lang);
assert(kwd == K_STUDY); assert(kwd == K_STUDY);
init_tokens_str(skillname(sk, lang)); init_tokens_str(skillname(sk, lang));