cppcheck warnings for battle

This commit is contained in:
Enno Rehling 2018-02-25 14:18:36 +01:00
parent b67db4faf9
commit e4aa8f505e
6 changed files with 14 additions and 26 deletions

View File

@ -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;

View File

@ -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<EFBFBD>mpfen k<EFBFBD>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);

View File

@ -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);

View File

@ -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");
}

View File

@ -8,6 +8,12 @@
#include <assert.h>
#include <string.h>
#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);

View File

@ -1,10 +1,4 @@
#include <stddef.h>
#ifdef WIN32
#define PATH_DELIM '\\'
#else
#define PATH_DELIM '/'
#endif
char * path_join(const char *p1, const char *p2, char *dst, size_t len);