Merge pull request #367 from ennorehling/coverity-scan

Coverity scan fixes, part n+1
This commit is contained in:
Enno Rehling 2015-11-05 09:30:55 +01:00
commit c0af920d0d
10 changed files with 45 additions and 42 deletions

View File

@ -335,3 +335,14 @@ function test_stonegolems()
assert_equal(1 ,u2.number, "There shoud be one Stone Golems") assert_equal(1 ,u2.number, "There shoud be one Stone Golems")
-- end test Stone Golems four stones -- end test Stone Golems four stones
end end
function test_birthdaycake()
r = region.create(0,0, "plain")
f = faction.create("cake@eressea.de", "human", "de")
u = unit.create(f, r, 1)
u:add_item("birthdaycake", 1)
u:clear_orders()
u:add_order("ZEIGE Geburtstagstorte")
process_orders()
end

View File

@ -193,11 +193,9 @@ static int tolua_building_create(lua_State * L)
const char *bname = tolua_tostring(L, 2, 0); const char *bname = tolua_tostring(L, 2, 0);
if (!r) { if (!r) {
log_error("building.create expects a region as argument 1"); log_error("building.create expects a region as argument 1");
} } else if (!bname) {
if (!bname) {
log_error("building.create expects a name as argument 2"); log_error("building.create expects a name as argument 2");
} } else {
if (bname) {
const building_type *btype = bt_find(bname); const building_type *btype = bt_find(bname);
if (btype) { if (btype) {
building *b = new_building(btype, r, default_locale); building *b = new_building(btype, r, default_locale);

View File

@ -746,7 +746,6 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
building *b; building *b;
const char *pzTmp; const char *pzTmp;
skill *sv; skill *sv;
const attrib *a_fshidden = NULL;
bool itemcloak = false; bool itemcloak = false;
static const curse_type *itemcloak_ct = 0; static const curse_type *itemcloak_ct = 0;
static bool init = false; static bool init = false;
@ -834,13 +833,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
stream_printf(out, "\"%s\";typprefix\n", translate(prefix, LOC(f->locale, stream_printf(out, "\"%s\";typprefix\n", translate(prefix, LOC(f->locale,
prefix))); prefix)));
} }
if (u->faction != f && a_fshidden stream_printf(out, "%d;Anzahl\n", u->number);
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH, 0) >= 6) {
stream_printf(out, "-1;Anzahl\n");
}
else {
stream_printf(out, "%d;Anzahl\n", u->number);
}
pzTmp = get_racename(u->attribs); pzTmp = get_racename(u->attribs);
if (pzTmp) { if (pzTmp) {
@ -981,8 +974,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
if (f == u->faction || omniscient(f)) { if (f == u->faction || omniscient(f)) {
show = u->items; show = u->items;
} }
else if (!itemcloak && mode >= see_unit && !(a_fshidden else if (!itemcloak && mode >= see_unit) {
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH, 0) >= 3)) {
int n = report_items(u->items, result, MAX_INVENTORY, u, f); int n = report_items(u->items, result, MAX_INVENTORY, u, f);
assert(n >= 0); assert(n >= 0);
if (n > 0) if (n > 0)

View File

@ -983,6 +983,7 @@ static void handlekey(state * st, int c)
statusline(st->wnd_status->handle, "info-buildings true"); statusline(st->wnd_status->handle, "info-buildings true");
else else
statusline(st->wnd_status->handle, "info-buildings false"); statusline(st->wnd_status->handle, "info-buildings false");
break;
case 'f': case 'f':
st->info_flags ^= IFL_FACTIONS; st->info_flags ^= IFL_FACTIONS;
if (st->info_flags & IFL_FACTIONS) if (st->info_flags & IFL_FACTIONS)
@ -1245,7 +1246,7 @@ void run_mapper(void)
curs_set(1); curs_set(1);
set_readline(curses_readline); set_readline(curses_readline);
assert(stdscr);
getbegyx(stdscr, x, y); getbegyx(stdscr, x, y);
width = getmaxx(stdscr); width = getmaxx(stdscr);
height = getmaxy(stdscr); height = getmaxy(stdscr);

View File

@ -151,14 +151,13 @@ connection *get_borders(const region * r1, const region * r2)
connection *new_border(border_type * type, region * from, region * to) connection *new_border(border_type * type, region * from, region * to)
{ {
connection *b = calloc(1, sizeof(struct connection)); connection *b, **bp = get_borders_i(from, to);
if (from && to) { assert(from && to);
connection **bp = get_borders_i(from, to); while (*bp) {
while (*bp) bp = &(*bp)->next;
bp = &(*bp)->next;
*bp = b;
} }
*bp = b = calloc(1, sizeof(connection));
b->type = type; b->type = type;
b->from = from; b->from = from;
b->to = to; b->to = to;

View File

@ -1013,7 +1013,7 @@ void transfermen(unit * u, unit * dst, int n)
sn->level = (unsigned char)level; sn->level = (unsigned char)level;
sn->weeks = (unsigned char)weeks; sn->weeks = (unsigned char)weeks;
assert(sn->weeks > 0 && sn->weeks <= sn->level * 2 + 1); assert(sn->weeks > 0 && sn->weeks <= sn->level * 2 + 1);
assert(dst->number != 0 || (sn->level == sv->level assert(dst->number != 0 || (sv && sn->level == sv->level
&& sn->weeks == sv->weeks)); && sn->weeks == sv->weeks));
} }
else if (sn) { else if (sn) {

View File

@ -1321,7 +1321,7 @@ static const region_list *cap_route(region * r, const region_list * route,
region *current = r; region *current = r;
int moves = speed; int moves = speed;
const region_list *iroute = route; const region_list *iroute = route;
while (iroute != route_end) { while (iroute && iroute != route_end) {
region *next = iroute->data; region *next = iroute->data;
direction_t reldir = reldirection(current, next); direction_t reldir = reldirection(current, next);
@ -2192,8 +2192,8 @@ static void travel(unit * u, region_list ** routep)
region_list *route_begin = NULL; region_list *route_begin = NULL;
follower *followers = NULL; follower *followers = NULL;
if (routep) assert(routep);
*routep = NULL; *routep = NULL;
/* a few pre-checks that need not be done for each step: */ /* a few pre-checks that need not be done for each step: */
if (!fval(r->terrain, SEA_REGION)) { if (!fval(r->terrain, SEA_REGION)) {

View File

@ -580,8 +580,8 @@ volcano_destruction(region * volcano, region * r, const char *damage)
rsettrees(r, 0, 0); rsettrees(r, 0, 0);
a = a_find(r->attribs, &at_reduceproduction); a = a_find(r->attribs, &at_reduceproduction);
if (!a) { if (a) {
a = make_reduceproduction(percent, time); a = a_add(&r->attribs, make_reduceproduction(percent, time));
} }
else { else {
/* Produktion vierteln ... */ /* Produktion vierteln ... */

View File

@ -456,7 +456,6 @@ size_t size)
building *b; building *b;
bool isbattle = (bool)(mode == see_battle); bool isbattle = (bool)(mode == see_battle);
int telepath_see = 0; int telepath_see = 0;
attrib *a_fshidden = NULL;
item *itm; item *itm;
item *show; item *show;
faction *fv = visible_faction(f, u); faction *fv = visible_faction(f, u);
@ -520,14 +519,8 @@ size_t size)
bufp = STRLCPY(bufp, ", ", size); bufp = STRLCPY(bufp, ", ", size);
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1 if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d ", u->number)))
&& effskill(u, SK_STEALTH, 0) >= 6) { WARN_STATIC_BUFFER();
bufp = STRLCPY(bufp, "? ", size);
}
else {
if (wrptr(&bufp, &size, _snprintf(bufp, size, "%d ", u->number)))
WARN_STATIC_BUFFER();
}
pzTmp = get_racename(u->attribs); pzTmp = get_racename(u->attribs);
if (pzTmp) { if (pzTmp) {
@ -607,8 +600,7 @@ size_t size)
if (f == u->faction || telepath_see || omniscient(f)) { if (f == u->faction || telepath_see || omniscient(f)) {
show = u->items; show = u->items;
} }
else if (!itemcloak && mode >= see_unit && !(a_fshidden else if (!itemcloak && mode >= see_unit) {
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH, 0) >= 3)) {
int n = report_items(u->items, results, MAX_INVENTORY, u, f); int n = report_items(u->items, results, MAX_INVENTORY, u, f);
assert(n >= 0); assert(n >= 0);
if (n > 0) if (n > 0)
@ -1555,14 +1547,18 @@ int write_reports(faction * f, time_t ltime)
struct report_context ctx; struct report_context ctx;
const char *encoding = "UTF-8"; const char *encoding = "UTF-8";
report_type *rtype; report_type *rtype;
const char *path = reportpath();;
if (noreports) { if (noreports) {
return false; return false;
} }
prepare_report(&ctx, f); prepare_report(&ctx, f);
get_addresses(&ctx); get_addresses(&ctx);
if (_access(reportpath(), 0) < 0) { if (_access(path, 0) < 0) {
_mkdir(reportpath()); if (_mkdir(path) != 0) {
log_error("could not create reports directory %s: %s", path, strerror(errno));
abort();
}
} }
if (errno) { if (errno) {
log_warning("errno was %d before writing reports", errno); log_warning("errno was %d before writing reports", errno);
@ -1661,12 +1657,18 @@ int reports(void)
time_t ltime = time(NULL); time_t ltime = time(NULL);
int retval = 0; int retval = 0;
char path[MAX_PATH]; char path[MAX_PATH];
const char * rpath = reportpath();
log_info("Writing reports for turn %d:", turn); log_info("Writing reports for turn %d:", turn);
report_donations(); report_donations();
remove_empty_units(); remove_empty_units();
_mkdir(reportpath()); if (_access(rpath, 0) < 0) {
if (_mkdir(rpath) != 0) {
log_error("could not create reports directory %s: %s", rpath, strerror(errno));
abort();
}
}
sprintf(path, "%s/reports.txt", reportpath()); sprintf(path, "%s/reports.txt", reportpath());
mailit = fopen(path, "w"); mailit = fopen(path, "w");
if (mailit == NULL) { if (mailit == NULL) {

@ -1 +1 @@
Subproject commit 1d92cb36df41c183c378aad17cbbfc0eddbb5c84 Subproject commit 89f3c1b01e41f2675fcbfd51fd8494894dc22d44