try fixing coverity complaints

This commit is contained in:
Enno Rehling 2017-10-10 09:29:32 +02:00
parent 333ef06fef
commit 8a5164806b
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) {
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));