fixing new coverity scan defects

167039 Dereference after null check
167038 Unchecked return value
This commit is contained in:
Enno Rehling 2017-04-16 15:52:34 +02:00
parent 0b226ba75e
commit 51c2df62ca
2 changed files with 9 additions and 4 deletions

View File

@ -1505,6 +1505,7 @@ int owner_change(const region * r)
bool is_mourning(const region * r, int in_turn)
{
int change = owner_change(r);
return (change == in_turn - 1 && r->land->ownership->last_owner && r->land->ownership->owner
&& r->land->ownership->last_owner != r->land->ownership->owner);
return (change == in_turn - 1 && r->land &&
r->land->ownership->last_owner && r->land->ownership->owner &&
r->land->ownership->last_owner != r->land->ownership->owner);
}

View File

@ -1584,7 +1584,9 @@ int display_cmd(unit * u, struct order *ord)
free(*s);
if (s2) {
char * str = strdup(s2);
unicode_utf8_trim(str);
if (unicode_utf8_trim(str) != 0) {
log_info("trimming info: %s", s2);
}
if (strlen(str) >= DISPLAYSIZE) {
str[DISPLAYSIZE-1] = 0;
}
@ -1626,7 +1628,9 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2)
/* TODO: Validate to make sure people don't have illegal characters in
* names, phishing-style? () come to mind. */
strlcpy(name, s2, sizeof(name));
unicode_utf8_trim(name);
if (unicode_utf8_trim(name) != 0) {
log_info("trimming name: %s", s2);
}
free(*s);
*s = strdup(name);