enable -Wconversion on gcc/clang builds

fix some of the warnings coming out of that for battle.c
This commit is contained in:
Enno Rehling 2015-05-12 14:28:25 -07:00
parent c57907e340
commit a46d60aa97
4 changed files with 26 additions and 24 deletions

View File

@ -13,10 +13,10 @@ include_directories (${BSON_INCLUDE_DIR})
include_directories (${INIPARSER_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR})
IF(CMAKE_COMPILER_IS_GNUCC) IF(CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wconversion -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL")
elseif(MSVC) elseif(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG set(CMAKE_EXE_LINKER_FLAGS_DEBUG
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib") "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE set(CMAKE_EXE_LINKER_FLAGS_RELEASE

View File

@ -307,7 +307,7 @@ fighter *select_corpse(battle * b, fighter * af)
maxcasualties += s->casualties; maxcasualties += s->casualties;
} }
} }
di = rng_int() % maxcasualties; di = (int)(rng_int() % maxcasualties);
for (s = b->sides; s != b->sides + b->nsides; ++s) { for (s = b->sides; s != b->sides + b->nsides; ++s) {
for (df = s->fighters; df; df = df->next) { for (df = s->fighters; df; df = df->next) {
/* Geflohene haben auch 0 hp, dürfen hier aber nicht ausgewählt /* Geflohene haben auch 0 hp, dürfen hier aber nicht ausgewählt
@ -487,7 +487,7 @@ contest_classic(int skilldiff, const armor_type * ar, const armor_type * sh)
vw = (int)(100 - ((100 - vw) * mod)); vw = (int)(100 - ((100 - vw) * mod));
do { do {
p = rng_int() % 100; p = (int)(rng_int() % 100);
vw -= p; vw -= p;
} while (vw >= 0 && p >= 90); } while (vw >= 0 && p >= 90);
return (vw <= 0); return (vw <= 0);
@ -1019,7 +1019,8 @@ static int natural_armor(unit * du)
static int *bonus = 0; static int *bonus = 0;
int an = u_race(du)->armor; int an = u_race(du)->armor;
if (bonus == 0) { if (bonus == 0) {
bonus = calloc(sizeof(int), num_races); assert(num_races > 0);
bonus = calloc((size_t)num_races, sizeof(int));
} }
if (bonus[u_race(du)->index] == 0) { if (bonus[u_race(du)->index] == 0) {
bonus[u_race(du)->index] = bonus[u_race(du)->index] =
@ -1506,7 +1507,7 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select)
if (enemies <= 0) if (enemies <= 0)
return no_troop; return no_troop;
selected = rng_int() % enemies; selected = (int)(rng_int() % enemies);
for (si = 0; as->enemies[si]; ++si) { for (si = 0; as->enemies[si]; ++si) {
side *ds = as->enemies[si]; side *ds = as->enemies[si];
fighter *df; fighter *df;
@ -1866,9 +1867,9 @@ static void do_extra_spell(troop at, const att * a)
log_error("spell '%s' has no function.\n", sp->sname); log_error("spell '%s' has no function.\n", sp->sname);
} }
else { else {
int level = a->level; float force = (float)(a->level * MagicPower());
assert(a->level > 0); assert(a->level > 0);
cast_combatspell(at, sp, level, level * MagicPower()); cast_combatspell(at, sp, a->level, force);
} }
} }
@ -2468,7 +2469,7 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype)
if (!allies) { if (!allies) {
return no_troop; return no_troop;
} }
allies = rng_int() % allies; allies = (int)(rng_int() % allies);
for (ds = b->sides; ds != b->sides + b->nsides; ++ds) { for (ds = b->sides; ds != b->sides + b->nsides; ++ds) {
if ((allytype == ALLY_ANY && helping(as, ds)) || (allytype == ALLY_SELF if ((allytype == ALLY_ANY && helping(as, ds)) || (allytype == ALLY_SELF
@ -2503,7 +2504,7 @@ static int loot_quota(const unit * src, const unit * dst,
assert(divisor == 0 || divisor >= 1); assert(divisor == 0 || divisor >= 1);
} }
if (divisor >= 1) { if (divisor >= 1) {
double r = n / divisor; double r = (float)n / divisor;
int x = (int)r; int x = (int)r;
r = r - x; r = r - x;
@ -2527,8 +2528,8 @@ static void loot_items(fighter * corpse)
return; return;
while (itm) { while (itm) {
float lootfactor = dead / (float)u->number; /* only loot the dead! */ float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */
int maxloot = (int)(itm->number * lootfactor); int maxloot = (int)((float)itm->number * lootfactor);
if (maxloot > 0) { if (maxloot > 0) {
int i = _min(10, maxloot); int i = _min(10, maxloot);
for (; i != 0; --i) { for (; i != 0; --i) {
@ -2863,7 +2864,7 @@ static void aftermath(battle * b)
float dmg = float dmg =
get_param_flt(global.parameters, "rules.ship.damage.battleround", get_param_flt(global.parameters, "rules.ship.damage.battleround",
0.05F); 0.05F);
damage_ship(sh, dmg * n); damage_ship(sh, dmg * (float)n);
freset(sh, SF_DAMAGED); freset(sh, SF_DAMAGED);
} }
} }
@ -3176,7 +3177,7 @@ side * get_side(battle * b, const struct unit * u)
return 0; return 0;
} }
side * find_side(battle * b, const faction * f, const group * g, int flags, const faction * stealthfaction) side * find_side(battle * b, const faction * f, const group * g, unsigned int flags, const faction * stealthfaction)
{ {
side * s; side * s;
static int rule_anon_battle = -1; static int rule_anon_battle = -1;
@ -3186,8 +3187,8 @@ side * find_side(battle * b, const faction * f, const group * g, int flags, cons
} }
for (s = b->sides; s != b->sides + b->nsides; ++s) { for (s = b->sides; s != b->sides + b->nsides; ++s) {
if (s->faction == f && s->group == g) { if (s->faction == f && s->group == g) {
int s1flags = flags | SIDE_HASGUARDS; unsigned int s1flags = flags | SIDE_HASGUARDS;
int s2flags = s->flags | SIDE_HASGUARDS; unsigned int s2flags = s->flags | SIDE_HASGUARDS;
if (rule_anon_battle && s->stealthfaction != stealthfaction) { if (rule_anon_battle && s->stealthfaction != stealthfaction) {
continue; continue;
} }
@ -3205,7 +3206,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
weapon weapons[WMAX]; weapon weapons[WMAX];
int owp[WMAX]; int owp[WMAX];
int dwp[WMAX]; int dwp[WMAX];
int w = 0;
region *r = b->region; region *r = b->region;
item *itm; item *itm;
fighter *fig = NULL; fighter *fig = NULL;
@ -3271,7 +3271,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
fig->catmsg = -1; fig->catmsg = -1;
/* Freigeben nicht vergessen! */ /* Freigeben nicht vergessen! */
fig->person = (struct person*)calloc(fig->alive, sizeof(struct person)); assert(fig->alive > 0);
fig->person = (struct person*)calloc((size_t)fig->alive, sizeof(struct person));
h = u->hp / u->number; h = u->hp / u->number;
assert(h); assert(h);
@ -3330,7 +3331,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
/* Für alle Waffengattungen wird bestimmt, wie viele der Personen mit /* Für alle Waffengattungen wird bestimmt, wie viele der Personen mit
* ihr kämpfen könnten, und was ihr Wert darin ist. */ * ihr kämpfen könnten, und was ihr Wert darin ist. */
if (u_race(u)->battle_flags & BF_EQUIPMENT) { if (u_race(u)->battle_flags & BF_EQUIPMENT) {
int oi = 0, di = 0; int oi = 0, di = 0, w = 0;
for (itm = u->items; itm && w != WMAX; itm = itm->next) { for (itm = u->items; itm && w != WMAX; itm = itm->next) {
const weapon_type *wtype = resource2weapon(itm->type->rtype); const weapon_type *wtype = resource2weapon(itm->type->rtype);
if (wtype == NULL || itm->number == 0) if (wtype == NULL || itm->number == 0)
@ -3345,8 +3346,9 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
} }
assert(w != WMAX); assert(w != WMAX);
} }
fig->weapons = (weapon *)calloc(sizeof(weapon), w + 1); assert(w >= 0);
memcpy(fig->weapons, weapons, w * sizeof(weapon)); fig->weapons = (weapon *)calloc(sizeof(weapon), (size_t)(w + 1));
memcpy(fig->weapons, weapons, (size_t)(w * sizeof(weapon)));
for (i = 0; i != w; ++i) { for (i = 0; i != w; ++i) {
int j, o = 0, d = 0; int j, o = 0, d = 0;
@ -3485,7 +3487,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
int rnd; int rnd;
do { do {
rnd = rng_int() % 100; rnd = (int)(rng_int() % 100);
if (rnd >= 40 && rnd <= 69) if (rnd >= 40 && rnd <= 69)
p_bonus += 1; p_bonus += 1;
else if (rnd <= 89) else if (rnd <= 89)

View File

@ -227,7 +227,7 @@ extern "C" {
/* BEGIN battle interface */ /* BEGIN battle interface */
void battle_init(battle * b); void battle_init(battle * b);
void battle_free(battle * b); void battle_free(battle * b);
side * find_side(battle * b, const struct faction * f, const struct group * g, int flags, const struct faction * stealthfaction); side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
side * get_side(battle * b, const struct unit * u); side * get_side(battle * b, const struct unit * u);
fighter * get_fighter(battle * b, const struct unit * u); fighter * get_fighter(battle * b, const struct unit * u);
/* END battle interface */ /* END battle interface */

View File

@ -908,7 +908,7 @@ static int sp_summonent(castorder * co)
return 0; return 0;
} }
ents = (int)_min(power * power, rtrees(r, 2)); ents = _min((int)(power * power), rtrees(r, 2));
u = create_unit(r, mage->faction, ents, get_race(RC_TREEMAN), 0, NULL, mage); u = create_unit(r, mage->faction, ents, get_race(RC_TREEMAN), 0, NULL, mage);