From 079a55fe41bc9d63c7c53b7a5d607dbce4dcb461 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 20:06:47 +0100 Subject: [PATCH] cppcheck warnings --- src/kernel/build.c | 20 ++++++++++---------- src/kernel/building.test.c | 2 +- src/orderfile.c | 7 ++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 686964481..b2774fbd7 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -476,14 +476,14 @@ static int count_materials(unit *u, const construction *type, int n, int complet assert(canuse >= 0); if (type->reqsize > 1) { - int need, prebuilt; - prebuilt = - required(completed, type->reqsize, type->materials[c].number); - for (; n;) { - need = + int prebuilt = required(completed, type->reqsize, + type->materials[c].number); + while (n > 0) { + int need = required(completed + n, type->reqsize, type->materials[c].number); - if (need - prebuilt <= canuse) + if (need - prebuilt <= canuse) { break; + } --n; /* TODO: optimieren? */ } } @@ -704,7 +704,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * * gefunden wurde, dann wird nicht einfach eine neue erbaut. Ansonsten * baut man an der eigenen burg weiter. */ - /* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */ + /* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */ if (id > 0) { /* eine Nummer angegeben, keine neue Burg bauen */ b = findbuilding(id); if (!b || b->region != u->region) { /* eine Burg mit dieser Nummer gibt es hier nicht */ @@ -893,12 +893,12 @@ static void build_ship(unit * u, ship * sh, int want) if (n) ADDMSG(&u->faction->msgs, - msg_message("buildship", "ship unit size", sh, u, n)); + msg_message("buildship", "ship unit size", sh, u, n)); } void create_ship(unit * u, const struct ship_type *newtype, int want, -order * ord) + order * ord) { ship *sh; int msize; @@ -940,7 +940,7 @@ order * ord) } new_order = create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale, - parameters[P_SHIP]), sh->no); + parameters[P_SHIP]), sh->no); replace_order(&u->orders, ord, new_order); free_order(new_order); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 8d5b86dc9..de34d59b5 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -247,7 +247,7 @@ static void test_buildingowner_resets_when_empty(CuTest * tc) u_set_building(u, bld); CuAssertPtrEquals(tc, u, building_owner(bld)); u->number = 0; - CuAssertPtrEquals(tc, 0, building_owner(bld)); + CuAssertPtrEquals(tc, NULL, building_owner(bld)); u->number = 1; CuAssertPtrEquals(tc, u, building_owner(bld)); test_teardown(); diff --git a/src/orderfile.c b/src/orderfile.c index ac80db0a2..1eca97686 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -121,10 +121,8 @@ static unit *unitorders(input *in, faction *f) static faction *factionorders(void) { - faction *f = NULL; int fid = getid(); - - f = findfaction(fid); + faction *f = findfaction(fid); if (f != NULL && !fval(f, FFL_NPC)) { char token[128]; @@ -231,9 +229,8 @@ int readorders(const char *filename) { input in; int result; + FILE *F = fopen(filename, "r"); - FILE *F = NULL; - F = fopen(filename, "r"); if (!F) { perror(filename); return -1;