fix some cppcheck warnings

This commit is contained in:
Enno Rehling 2018-02-11 15:43:24 +01:00
parent ff33073bd9
commit f67a4943e4
11 changed files with 13 additions and 54 deletions

View file

@ -472,16 +472,15 @@ static int count_materials(unit *u, const construction *type, int n, int complet
int c;
for (c = 0; n > 0 && type->materials[c].number; c++) {
const struct resource_type *rtype = type->materials[c].rtype;
int need, prebuilt;
int canuse = get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
canuse = matmod(u, rtype, canuse);
assert(canuse >= 0);
if (type->reqsize > 1) {
prebuilt =
int prebuilt =
required(completed, type->reqsize, type->materials[c].number);
for (; n;) {
need =
int need =
required(completed + n, type->reqsize, type->materials[c].number);
if (need - prebuilt <= canuse)
break;

View file

@ -147,39 +147,6 @@ const char *parameters[MAXPARAMS] = {
"ALLIANZ"
};
FILE *debug;
void
parse(keyword_t kword, int(*dofun) (unit *, struct order *), bool thisorder)
{
region *r;
for (r = regions; r; r = r->next) {
unit **up = &r->units;
while (*up) {
unit *u = *up;
order **ordp = &u->orders;
if (thisorder)
ordp = &u->thisorder;
while (*ordp) {
order *ord = *ordp;
if (getkeyword(ord) == kword) {
if (dofun(u, ord) != 0)
break;
if (u->orders == NULL)
break;
}
if (thisorder)
break;
if (*ordp == ord)
ordp = &ord->next;
}
if (*up == u)
up = &u->next;
}
}
}
int findoption(const char *s, const struct locale *lang)
{
void **tokens = get_translations(lang, UT_OPTIONS);

View file

@ -225,7 +225,7 @@ border_type *find_bordertype(const char *name)
void b_read(connection * b, gamedata * data)
{
storage * store = data->store;
int n, result = 0;
int n;
switch (b->type->datatype) {
case VAR_NONE:
case VAR_INT:
@ -240,9 +240,7 @@ void b_read(connection * b, gamedata * data)
case VAR_VOIDPTR:
default:
assert(!"invalid variant type in connection");
result = 0;
}
assert(result >= 0 || "EOF encountered?");
}
void b_write(const connection * b, storage * store)

View file

@ -242,10 +242,10 @@ order *create_order(keyword_t kwd, const struct locale * lang,
va_start(marker, params);
sbs_init(&sbs, zBuffer, sizeof(zBuffer));
while (*params) {
int i;
const char *s;
tok = strchr(params, '%');
if (tok) {
int i;
if (tok != params) {
sbs_strncat(&sbs, params, tok - params);
}

View file

@ -71,12 +71,12 @@ bool terrain_changed(int *cache) {
void free_terrains(void)
{
while (registered_terrains) {
int n;
terrain_type * t = registered_terrains;
registered_terrains = t->next;
free(t->_name);
free(t->herbs);
if (t->production) {
int n;
for (n = 0; t->production[n].type; ++n) {
free(t->production[n].base);
free(t->production[n].divisor);

View file

@ -807,9 +807,9 @@ static void smooth_island(region_list * island)
region_list *rlist = NULL;
for (rlist = island; rlist; rlist = rlist->next) {
region *r = rlist->data;
int n, nland = 0;
if (r->land) {
int n, nland = 0;
get_neighbours(r, rn);
for (n = 0; n != MAXDIRECTIONS && nland <= 1; ++n) {
if (rn[n]->land) {

View file

@ -301,7 +301,6 @@ order * ord)
attrib *a;
region *r;
unit *warden = findunit(atoi36("mwar"));
int unit_cookie;
UNUSED_ARG(amount);
@ -316,11 +315,11 @@ order * ord)
r = findregion(a->data.sa[0], a->data.sa[1]);
assert(r);
a_remove(&u->attribs, a);
/* Übergebene Gegenstände zurückgeben */
/* Übergebene Gegenstände zurückgeben */
a = a_find(u->attribs, &at_museumgivebackcookie);
if (a) {
unit_cookie = a->data.i;
int unit_cookie = a->data.i;
a_remove(&u->attribs, a);
for (a = a_find(warden->attribs, &at_museumgiveback);

View file

@ -43,7 +43,6 @@ void make_undead_unit(unit * u)
void age_undead(unit * u)
{
region *r = u->region;
int n = 0;
/* untote, die einer partei angehoeren, koennen sich
* absplitten, anstatt sich zu vermehren. monster
@ -51,10 +50,9 @@ void age_undead(unit * u)
if (u->number > UNDEAD_MIN && !is_monsters(u->faction)
&& rng_int() % 100 < UNDEAD_BREAKUP) {
int m;
int m, n = 0;
unit *u2;
n = 0;
for (m = u->number; m; m--) {
if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION)
++n;

View file

@ -111,7 +111,7 @@ trigger *trigger_changerace(struct unit * u, const struct race * prace,
trigger *t = t_new(&tt_changerace);
changerace_data *td = (changerace_data *)t->data.v;
assert(u_race(u) == u_irace(u) || "!changerace-triggers cannot stack!");
assert(u_race(u) == u_irace(u) || !"changerace-triggers cannot stack!");
td->u = u;
td->race = prace;
td->irace = irace;

View file

@ -257,8 +257,9 @@ static lstr lstrs[MAXLOCALES];
void ** get_translations(const struct locale *lang, int index)
{
assert(lang);
assert(lang->index < MAXLOCALES
|| "you have to increase MAXLOCALES and recompile");
if (lang->index >= MAXLOCALES) {
log_fatal("you have to increase MAXLOCALES and recompile");
}
if (lang->index < MAXLOCALES) {
return lstrs[lang->index].tokens + index;
}

View file

@ -108,9 +108,6 @@ int unicode_utf8_tolower(utf8_t * op, size_t outlen, const utf8_t * ip)
}
}
if (outlen <= 0) {
return ENOMEM;
}
*op = 0;
return 0;
}