From 51c2df62caa1d272f11a3b40dccb0572a7174f3f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 16 Apr 2017 15:52:34 +0200 Subject: [PATCH] fixing new coverity scan defects 167039 Dereference after null check 167038 Unchecked return value --- src/kernel/region.c | 5 +++-- src/laws.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 2a54a2eaa..0e45c59bb 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -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); } diff --git a/src/laws.c b/src/laws.c index adf8b9f11..af96a309c 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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);