diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e1a7bfca..ea2c8d0e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,10 +13,10 @@ include_directories (${BSON_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR}) 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") 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 "${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 diff --git a/src/battle.c b/src/battle.c index 1484ccfa3..803124b4d 100644 --- a/src/battle.c +++ b/src/battle.c @@ -307,7 +307,7 @@ fighter *select_corpse(battle * b, fighter * af) maxcasualties += s->casualties; } } - di = rng_int() % maxcasualties; + di = (int)(rng_int() % maxcasualties); for (s = b->sides; s != b->sides + b->nsides; ++s) { for (df = s->fighters; df; df = df->next) { /* 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)); do { - p = rng_int() % 100; + p = (int)(rng_int() % 100); vw -= p; } while (vw >= 0 && p >= 90); return (vw <= 0); @@ -1019,7 +1019,8 @@ static int natural_armor(unit * du) static int *bonus = 0; int an = u_race(du)->armor; 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) { bonus[u_race(du)->index] = @@ -1506,7 +1507,7 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select) if (enemies <= 0) return no_troop; - selected = rng_int() % enemies; + selected = (int)(rng_int() % enemies); for (si = 0; as->enemies[si]; ++si) { side *ds = as->enemies[si]; 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); } else { - int level = a->level; + float force = (float)(a->level * MagicPower()); 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) { return no_troop; } - allies = rng_int() % allies; + allies = (int)(rng_int() % allies); for (ds = b->sides; ds != b->sides + b->nsides; ++ds) { 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); } if (divisor >= 1) { - double r = n / divisor; + double r = (float)n / divisor; int x = (int)r; r = r - x; @@ -2527,8 +2528,8 @@ static void loot_items(fighter * corpse) return; while (itm) { - float lootfactor = dead / (float)u->number; /* only loot the dead! */ - int maxloot = (int)(itm->number * lootfactor); + float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */ + int maxloot = (int)((float)itm->number * lootfactor); if (maxloot > 0) { int i = _min(10, maxloot); for (; i != 0; --i) { @@ -2863,7 +2864,7 @@ static void aftermath(battle * b) float dmg = get_param_flt(global.parameters, "rules.ship.damage.battleround", 0.05F); - damage_ship(sh, dmg * n); + damage_ship(sh, dmg * (float)n); freset(sh, SF_DAMAGED); } } @@ -3176,7 +3177,7 @@ side * get_side(battle * b, const struct unit * u) 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; 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) { if (s->faction == f && s->group == g) { - int s1flags = flags | SIDE_HASGUARDS; - int s2flags = s->flags | SIDE_HASGUARDS; + unsigned int s1flags = flags | SIDE_HASGUARDS; + unsigned int s2flags = s->flags | SIDE_HASGUARDS; if (rule_anon_battle && s->stealthfaction != stealthfaction) { continue; } @@ -3205,7 +3206,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) weapon weapons[WMAX]; int owp[WMAX]; int dwp[WMAX]; - int w = 0; region *r = b->region; item *itm; fighter *fig = NULL; @@ -3271,7 +3271,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) fig->catmsg = -1; /* 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; 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 * ihr kämpfen könnten, und was ihr Wert darin ist. */ 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) { const weapon_type *wtype = resource2weapon(itm->type->rtype); if (wtype == NULL || itm->number == 0) @@ -3345,8 +3346,9 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) } assert(w != WMAX); } - fig->weapons = (weapon *)calloc(sizeof(weapon), w + 1); - memcpy(fig->weapons, weapons, w * sizeof(weapon)); + assert(w >= 0); + 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) { int j, o = 0, d = 0; @@ -3485,7 +3487,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) int rnd; do { - rnd = rng_int() % 100; + rnd = (int)(rng_int() % 100); if (rnd >= 40 && rnd <= 69) p_bonus += 1; else if (rnd <= 89) diff --git a/src/battle.h b/src/battle.h index d144da30d..9bf500ed9 100644 --- a/src/battle.h +++ b/src/battle.h @@ -227,7 +227,7 @@ extern "C" { /* BEGIN battle interface */ void battle_init(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); fighter * get_fighter(battle * b, const struct unit * u); /* END battle interface */ diff --git a/src/spells.c b/src/spells.c index 734858745..86154bd2e 100644 --- a/src/spells.c +++ b/src/spells.c @@ -908,7 +908,7 @@ static int sp_summonent(castorder * co) 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);