From e4aa8f505ecd93068cdc9497a4eb65355a9ae16d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Feb 2018 14:18:36 +0100 Subject: [PATCH] cppcheck warnings for battle --- src/attributes/dict.c | 6 ------ src/battle.c | 16 ++++++---------- src/battle.test.c | 4 +--- src/bind_config.c | 2 +- src/util/path.c | 6 ++++++ src/util/path.h | 6 ------ 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 83a53dbeb..8e7dfb20a 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -52,13 +52,7 @@ typedef struct dict_data { char *name; union { int i; - char *str; double real; - struct unit *u; - struct region *r; - struct building *b; - struct ship *sh; - struct faction *f; } data; } dict_data; diff --git a/src/battle.c b/src/battle.c index b7482e48a..306637db1 100644 --- a/src/battle.c +++ b/src/battle.c @@ -393,7 +393,6 @@ static int get_row(const side * s, int row, const side * vs) int line, result; int retreat = 0; int size[NUMROWS]; - int front = 0; battle *b = s->battle; memset(counted, 0, sizeof(counted)); @@ -426,6 +425,7 @@ static int get_row(const side * s, int row, const side * vs) break; } if (enemyfront) { + int front = 0; for (line = FIRST_ROW; line != NUMROWS; ++line) { front += size[line]; if (!front || front < enemyfront / ROW_FACTOR) @@ -1142,7 +1142,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* Schild */ side *ds = df->side; - int hp, ar; + int ar; const weapon_type *dwtype = NULL; const weapon_type *awtype = NULL; @@ -1257,7 +1257,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile) /* jeder Schaden wird um effect% reduziert bis der Schild duration * Trefferpunkte aufgefangen hat */ if (me->typ == SHIELD_REDUCE) { - hp = rda * (me->effect / 100); + int hp = rda * (me->effect / 100); rda -= hp; me->duration -= hp; } @@ -2875,12 +2875,9 @@ static void print_stats(battle * b) { side *s2; side *s; - int i = 0; for (s = b->sides; s != b->sides + b->nsides; ++s) { bfaction *bf; - ++i; - for (bf = b->factions; bf; bf = bf->next) { faction *f = bf->faction; const char *loc_army = LOC(f->locale, "battle_army"); @@ -3046,8 +3043,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) { #define WMAX 20 weapon weapons[WMAX]; - int owp[WMAX]; - int dwp[WMAX]; region *r = b->region; item *itm; fighter *fig = NULL; @@ -3160,6 +3155,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) /* F�r alle Waffengattungen wird bestimmt, wie viele der Personen mit * ihr k�mpfen k�nnten, und was ihr Wert darin ist. */ if (u_race(u)->battle_flags & BF_EQUIPMENT) { + int owp[WMAX]; + int dwp[WMAX]; int oi = 0, di = 0, w = 0; for (itm = u->items; itm && w != WMAX; itm = itm->next) { const weapon_type *wtype = resource2weapon(itm->type->rtype); @@ -3480,7 +3477,6 @@ static int battle_report(battle * b) { side *s, *s2; bool cont = false; - bool komma; bfaction *bf; for (s = b->sides; s != b->sides + b->nsides; ++s) { @@ -3503,6 +3499,7 @@ static int battle_report(battle * b) char buf[32 * MAXSIDES]; message *m; sbstring sbs; + bool komma = false; sbs_init(&sbs, buf, sizeof(buf)); battle_message_faction(b, fac, msg_separator); @@ -3514,7 +3511,6 @@ static int battle_report(battle * b) battle_message_faction(b, fac, m); msg_release(m); - komma = false; for (s = b->sides; s != b->sides + b->nsides; ++s) { if (s->alive) { int r, k = 0, *alive = get_alive(s); diff --git a/src/battle.test.c b/src/battle.test.c index d446cbebb..b69996ddf 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -446,7 +446,6 @@ static void test_battle_skilldiff(CuTest *tc) td.index = 0; ta.fighter = setup_fighter(&b, ua); ta.index = 0; - ua = test_create_unit(test_create_faction(NULL), r); CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0)); ta.fighter->person[0].attack = 2; @@ -483,7 +482,6 @@ static void test_battle_skilldiff_building(CuTest *tc) td.index = 0; ta.fighter = setup_fighter(&b, ua); ta.index = 0; - ua = test_create_unit(test_create_faction(NULL), r); CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0)); ud->building->size = 10; @@ -502,8 +500,8 @@ static void test_battle_skilldiff_building(CuTest *tc) static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax) { skill *sv = unit_skill(u, sk); - char buf[256]; if (sv) { + char buf[256]; sprintf(buf, "%s level %d != %d", msg, sv->level, level); CuAssertIntEquals_Msg(tc, buf, level, sv->level); sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax); diff --git a/src/bind_config.c b/src/bind_config.c index 83c65364d..2d4086ccf 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -63,11 +63,11 @@ int config_parse(const char *json) int config_read(const char *filename, const char * relpath) { - char name[PATH_MAX]; FILE *F; json_relpath = relpath; if (relpath) { + char name[PATH_MAX]; path_join(relpath, filename, name, sizeof(name)); F = fopen(name, "r"); } diff --git a/src/util/path.c b/src/util/path.c index 3ede6b4ee..bdbf7646d 100644 --- a/src/util/path.c +++ b/src/util/path.c @@ -8,6 +8,12 @@ #include #include +#ifdef WIN32 +#define PATH_DELIM '\\' +#else +#define PATH_DELIM '/' +#endif + char * path_join(const char *p1, const char *p2, char *dst, size_t len) { size_t sz; assert(p1 && p2); diff --git a/src/util/path.h b/src/util/path.h index 58e505df9..5a4e22270 100644 --- a/src/util/path.h +++ b/src/util/path.h @@ -1,10 +1,4 @@ #include -#ifdef WIN32 -#define PATH_DELIM '\\' -#else -#define PATH_DELIM '/' -#endif - char * path_join(const char *p1, const char *p2, char *dst, size_t len);