forked from github/server
fix some cppcheck warnings
This commit is contained in:
parent
ff33073bd9
commit
f67a4943e4
11 changed files with 13 additions and 54 deletions
|
@ -472,16 +472,15 @@ static int count_materials(unit *u, const construction *type, int n, int complet
|
||||||
int c;
|
int c;
|
||||||
for (c = 0; n > 0 && type->materials[c].number; c++) {
|
for (c = 0; n > 0 && type->materials[c].number; c++) {
|
||||||
const struct resource_type *rtype = type->materials[c].rtype;
|
const struct resource_type *rtype = type->materials[c].rtype;
|
||||||
int need, prebuilt;
|
|
||||||
int canuse = get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
|
int canuse = get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
|
||||||
canuse = matmod(u, rtype, canuse);
|
canuse = matmod(u, rtype, canuse);
|
||||||
|
|
||||||
assert(canuse >= 0);
|
assert(canuse >= 0);
|
||||||
if (type->reqsize > 1) {
|
if (type->reqsize > 1) {
|
||||||
prebuilt =
|
int prebuilt =
|
||||||
required(completed, type->reqsize, type->materials[c].number);
|
required(completed, type->reqsize, type->materials[c].number);
|
||||||
for (; n;) {
|
for (; n;) {
|
||||||
need =
|
int need =
|
||||||
required(completed + n, type->reqsize, type->materials[c].number);
|
required(completed + n, type->reqsize, type->materials[c].number);
|
||||||
if (need - prebuilt <= canuse)
|
if (need - prebuilt <= canuse)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -147,39 +147,6 @@ const char *parameters[MAXPARAMS] = {
|
||||||
"ALLIANZ"
|
"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)
|
int findoption(const char *s, const struct locale *lang)
|
||||||
{
|
{
|
||||||
void **tokens = get_translations(lang, UT_OPTIONS);
|
void **tokens = get_translations(lang, UT_OPTIONS);
|
||||||
|
|
|
@ -225,7 +225,7 @@ border_type *find_bordertype(const char *name)
|
||||||
void b_read(connection * b, gamedata * data)
|
void b_read(connection * b, gamedata * data)
|
||||||
{
|
{
|
||||||
storage * store = data->store;
|
storage * store = data->store;
|
||||||
int n, result = 0;
|
int n;
|
||||||
switch (b->type->datatype) {
|
switch (b->type->datatype) {
|
||||||
case VAR_NONE:
|
case VAR_NONE:
|
||||||
case VAR_INT:
|
case VAR_INT:
|
||||||
|
@ -240,9 +240,7 @@ void b_read(connection * b, gamedata * data)
|
||||||
case VAR_VOIDPTR:
|
case VAR_VOIDPTR:
|
||||||
default:
|
default:
|
||||||
assert(!"invalid variant type in connection");
|
assert(!"invalid variant type in connection");
|
||||||
result = 0;
|
|
||||||
}
|
}
|
||||||
assert(result >= 0 || "EOF encountered?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void b_write(const connection * b, storage * store)
|
void b_write(const connection * b, storage * store)
|
||||||
|
|
|
@ -242,10 +242,10 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
||||||
va_start(marker, params);
|
va_start(marker, params);
|
||||||
sbs_init(&sbs, zBuffer, sizeof(zBuffer));
|
sbs_init(&sbs, zBuffer, sizeof(zBuffer));
|
||||||
while (*params) {
|
while (*params) {
|
||||||
int i;
|
|
||||||
const char *s;
|
const char *s;
|
||||||
tok = strchr(params, '%');
|
tok = strchr(params, '%');
|
||||||
if (tok) {
|
if (tok) {
|
||||||
|
int i;
|
||||||
if (tok != params) {
|
if (tok != params) {
|
||||||
sbs_strncat(&sbs, params, tok - params);
|
sbs_strncat(&sbs, params, tok - params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,12 +71,12 @@ bool terrain_changed(int *cache) {
|
||||||
void free_terrains(void)
|
void free_terrains(void)
|
||||||
{
|
{
|
||||||
while (registered_terrains) {
|
while (registered_terrains) {
|
||||||
int n;
|
|
||||||
terrain_type * t = registered_terrains;
|
terrain_type * t = registered_terrains;
|
||||||
registered_terrains = t->next;
|
registered_terrains = t->next;
|
||||||
free(t->_name);
|
free(t->_name);
|
||||||
free(t->herbs);
|
free(t->herbs);
|
||||||
if (t->production) {
|
if (t->production) {
|
||||||
|
int n;
|
||||||
for (n = 0; t->production[n].type; ++n) {
|
for (n = 0; t->production[n].type; ++n) {
|
||||||
free(t->production[n].base);
|
free(t->production[n].base);
|
||||||
free(t->production[n].divisor);
|
free(t->production[n].divisor);
|
||||||
|
|
|
@ -807,9 +807,9 @@ static void smooth_island(region_list * island)
|
||||||
region_list *rlist = NULL;
|
region_list *rlist = NULL;
|
||||||
for (rlist = island; rlist; rlist = rlist->next) {
|
for (rlist = island; rlist; rlist = rlist->next) {
|
||||||
region *r = rlist->data;
|
region *r = rlist->data;
|
||||||
int n, nland = 0;
|
|
||||||
|
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
|
int n, nland = 0;
|
||||||
get_neighbours(r, rn);
|
get_neighbours(r, rn);
|
||||||
for (n = 0; n != MAXDIRECTIONS && nland <= 1; ++n) {
|
for (n = 0; n != MAXDIRECTIONS && nland <= 1; ++n) {
|
||||||
if (rn[n]->land) {
|
if (rn[n]->land) {
|
||||||
|
|
|
@ -301,7 +301,6 @@ order * ord)
|
||||||
attrib *a;
|
attrib *a;
|
||||||
region *r;
|
region *r;
|
||||||
unit *warden = findunit(atoi36("mwar"));
|
unit *warden = findunit(atoi36("mwar"));
|
||||||
int unit_cookie;
|
|
||||||
|
|
||||||
UNUSED_ARG(amount);
|
UNUSED_ARG(amount);
|
||||||
|
|
||||||
|
@ -316,11 +315,11 @@ order * ord)
|
||||||
r = findregion(a->data.sa[0], a->data.sa[1]);
|
r = findregion(a->data.sa[0], a->data.sa[1]);
|
||||||
assert(r);
|
assert(r);
|
||||||
a_remove(&u->attribs, a);
|
a_remove(&u->attribs, a);
|
||||||
/* Übergebene Gegenstände zurückgeben */
|
/* Übergebene Gegenstände zurückgeben */
|
||||||
|
|
||||||
a = a_find(u->attribs, &at_museumgivebackcookie);
|
a = a_find(u->attribs, &at_museumgivebackcookie);
|
||||||
if (a) {
|
if (a) {
|
||||||
unit_cookie = a->data.i;
|
int unit_cookie = a->data.i;
|
||||||
a_remove(&u->attribs, a);
|
a_remove(&u->attribs, a);
|
||||||
|
|
||||||
for (a = a_find(warden->attribs, &at_museumgiveback);
|
for (a = a_find(warden->attribs, &at_museumgiveback);
|
||||||
|
|
|
@ -43,7 +43,6 @@ void make_undead_unit(unit * u)
|
||||||
void age_undead(unit * u)
|
void age_undead(unit * u)
|
||||||
{
|
{
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
/* untote, die einer partei angehoeren, koennen sich
|
/* untote, die einer partei angehoeren, koennen sich
|
||||||
* absplitten, anstatt sich zu vermehren. monster
|
* absplitten, anstatt sich zu vermehren. monster
|
||||||
|
@ -51,10 +50,9 @@ void age_undead(unit * u)
|
||||||
|
|
||||||
if (u->number > UNDEAD_MIN && !is_monsters(u->faction)
|
if (u->number > UNDEAD_MIN && !is_monsters(u->faction)
|
||||||
&& rng_int() % 100 < UNDEAD_BREAKUP) {
|
&& rng_int() % 100 < UNDEAD_BREAKUP) {
|
||||||
int m;
|
int m, n = 0;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
|
|
||||||
n = 0;
|
|
||||||
for (m = u->number; m; m--) {
|
for (m = u->number; m; m--) {
|
||||||
if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION)
|
if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION)
|
||||||
++n;
|
++n;
|
||||||
|
|
|
@ -111,7 +111,7 @@ trigger *trigger_changerace(struct unit * u, const struct race * prace,
|
||||||
trigger *t = t_new(&tt_changerace);
|
trigger *t = t_new(&tt_changerace);
|
||||||
changerace_data *td = (changerace_data *)t->data.v;
|
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->u = u;
|
||||||
td->race = prace;
|
td->race = prace;
|
||||||
td->irace = irace;
|
td->irace = irace;
|
||||||
|
|
|
@ -257,8 +257,9 @@ static lstr lstrs[MAXLOCALES];
|
||||||
void ** get_translations(const struct locale *lang, int index)
|
void ** get_translations(const struct locale *lang, int index)
|
||||||
{
|
{
|
||||||
assert(lang);
|
assert(lang);
|
||||||
assert(lang->index < MAXLOCALES
|
if (lang->index >= MAXLOCALES) {
|
||||||
|| "you have to increase MAXLOCALES and recompile");
|
log_fatal("you have to increase MAXLOCALES and recompile");
|
||||||
|
}
|
||||||
if (lang->index < MAXLOCALES) {
|
if (lang->index < MAXLOCALES) {
|
||||||
return lstrs[lang->index].tokens + index;
|
return lstrs[lang->index].tokens + index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
*op = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue