From dd8449783a573cadd669f62a47e18abf8d25ac34 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 May 2015 19:08:44 +0200 Subject: [PATCH 1/4] converting float->double in a lot of the code to prevent -Wconversion messages --- src/attributes/movement.c | 7 +++++- src/battle.c | 6 ++--- src/give.c | 2 +- src/items.c | 10 ++++---- src/kernel/build.c | 6 ++--- src/kernel/config.c | 2 +- src/kernel/curse.c | 22 ++++++++---------- src/kernel/curse.h | 14 ++++++------ src/kernel/region.c | 5 ++-- src/kernel/region.h | 4 ++-- src/laws.c | 48 +++++++++++++++++++-------------------- src/magic.c | 18 +++++++-------- src/magic.h | 4 ++-- src/modules/score.c | 4 ++-- src/randenc.c | 2 +- src/randenc.h | 6 ++--- src/spells.c | 4 ++-- 17 files changed, 83 insertions(+), 81 deletions(-) diff --git a/src/attributes/movement.c b/src/attributes/movement.c index 662affdf3..beb3998f0 100644 --- a/src/attributes/movement.c +++ b/src/attributes/movement.c @@ -25,6 +25,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include +#include +#include + static void write_movement(const attrib * a, const void *owner, struct storage *store) { @@ -65,7 +68,9 @@ void set_movement(attrib ** alist, int type) static int age_speedup(attrib * a) { if (a->data.sa[0] > 0) { - a->data.sa[0] = a->data.sa[0] - a->data.sa[1]; + assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN); + assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX); + a->data.sa[0] = (short)(a->data.sa[0] - a->data.sa[1]); } return (a->data.sa[0] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } diff --git a/src/battle.c b/src/battle.c index feebe80d4..1ed7df3b0 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1771,7 +1771,7 @@ void do_combatmagic(battle * b, combatmagic_t was) } } -static int cast_combatspell(troop at, const spell * sp, int level, float force) +static int cast_combatspell(troop at, const spell * sp, int level, double force) { castorder co; @@ -1794,7 +1794,7 @@ static void do_combatspell(troop at) region *r = b->region; quicklist *ql; int level, qi; - float power; + double power; int fumblechance = 0; order *ord; int sl; @@ -1867,7 +1867,7 @@ static void do_extra_spell(troop at, const att * a) log_error("spell '%s' has no function.\n", sp->sname); } else { - float force = (float)a->level * MagicPower(); + double force = a->level * MagicPower(); assert(a->level > 0); cast_combatspell(at, sp, a->level, force); } diff --git a/src/give.c b/src/give.c index d22a09c73..d211a5518 100644 --- a/src/give.c +++ b/src/give.c @@ -131,7 +131,7 @@ static bool limited_give(const item_type * type) int give_quota(const unit * src, const unit * dst, const item_type * type, int n) { - float divisor; + double divisor; if (!limited_give(type)) { return n; diff --git a/src/items.c b/src/items.c index d7c9efd5e..5e9a357e6 100644 --- a/src/items.c +++ b/src/items.c @@ -81,7 +81,7 @@ use_speedsail(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { curse *c; - float effect; + double effect; ship *sh = u->ship; if (!sh) { cmistake(u, ord, 20, MSG_MOVE); @@ -120,7 +120,7 @@ struct order *ord) } for (i = 0; i != amount; ++i) { int effect, duration = 2; - float force; + double force; spell *sp = find_spell("antimagiczone"); attrib **ap = &r->attribs; unused_arg(ord); @@ -132,7 +132,7 @@ struct order *ord) /* Hält Sprüche bis zu einem summierten Gesamtlevel von power aus. * Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone * um seine Stufe */ - force = (float)effect * 20; /* Stufe 5 =~ 100 */ + force = effect * 20; /* Stufe 5 =~ 100 */ /* Regionszauber auflösen */ while (*ap && force > 0) { @@ -163,8 +163,8 @@ struct order *ord) } if (force > 0) { - create_curse(u, &r->attribs, ct_find("antimagiczone"), (float)force, duration, - (float)effect, 0); + create_curse(u, &r->attribs, ct_find("antimagiczone"), force, duration, + effect, 0); } } use_pooled(u, rt_crystal, GET_DEFAULT, amount); diff --git a/src/kernel/build.c b/src/kernel/build.c index cfebbfff7..bca970fc4 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -101,7 +101,7 @@ static void destroy_road(unit * u, int nmax, struct order *ord) else { unit *u2; region *r = u->region; - short road, n = (short)nmax; + int road, n = nmax; if (nmax > SHRT_MAX) { n = SHRT_MAX; @@ -131,7 +131,7 @@ static void destroy_road(unit * u, int nmax, struct order *ord) if (willdo > SHRT_MAX) road = 0; else - road = road - (short)willdo; + road = (short)(road - willdo); rsetroad(r, d, road); ADDMSG(&u->faction->msgs, msg_message("destroy_road", "unit from to", u, r, r2)); @@ -360,7 +360,7 @@ void build_road(region * r, unit * u, int size, direction_t d) /* n is now modified by several special effects, so we have to * minimize it again to make sure the road will not grow beyond * maximum. */ - rsetroad(r, d, rroad(r, d) + (short)n); + rsetroad(r, d, rroad(r, d) + n); if (u_race(u) == get_race(RC_STONEGOLEM)) { int golemsused = n / GOLEM_STONE; diff --git a/src/kernel/config.c b/src/kernel/config.c index 2e0f2c32c..b310d3fd6 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -853,7 +853,7 @@ int forbiddenid(int id) ++len; forbid = calloc(len, sizeof(int)); for (i = 0; i != len; ++i) { - forbid[i] = strtol(forbidden[i], NULL, 36); + forbid[i] = atoi36(forbidden[i]); } } for (i = 0; i != len; ++i) diff --git a/src/kernel/curse.c b/src/kernel/curse.c index d01e8900c..0cad2dfa6 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -392,15 +392,13 @@ bool remove_curse(attrib ** ap, const curse * c) /* gibt die allgemeine Stärke der Verzauberung zurück. id2 wird wie * oben benutzt. Dies ist nicht die Wirkung, sondern die Kraft und * damit der gegen Antimagie wirkende Widerstand einer Verzauberung */ -static float get_cursevigour(const curse * c) +static double get_cursevigour(const curse * c) { - if (c) - return c->vigour; - return 0; + return c ? c->vigour : 0; } /* setzt die Stärke der Verzauberung auf i */ -static void set_cursevigour(curse * c, float vigour) +static void set_cursevigour(curse * c, double vigour) { assert(c && vigour > 0); c->vigour = vigour; @@ -410,7 +408,7 @@ static void set_cursevigour(curse * c, float vigour) * Stärke zurück. Sollte die Zauberstärke unter Null sinken, löst er * sich auf. */ -float curse_changevigour(attrib ** ap, curse * c, float vigour) +double curse_changevigour(attrib ** ap, curse * c, double vigour) { vigour += get_cursevigour(c); @@ -426,7 +424,7 @@ float curse_changevigour(attrib ** ap, curse * c, float vigour) /* ------------------------------------------------------------- */ -float curse_geteffect(const curse * c) +double curse_geteffect(const curse * c) { if (c == NULL) return 0; @@ -437,7 +435,7 @@ float curse_geteffect(const curse * c) int curse_geteffect_int(const curse * c) { - float effect = curse_geteffect(c); + double effect = curse_geteffect(c); if (effect - (int)effect != 0) { log_error("curse has an integer attribute with float value: '%s' = %lf", c->type->cname, effect); @@ -491,7 +489,7 @@ static void set_cursedmen(curse * c, int cursedmen) * dieses Typs geben, gibt es den bestehenden zurück. */ static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct, - float vigour, int duration, float effect, int men) + double vigour, int duration, double effect, int men) { curse *c; attrib *a; @@ -528,7 +526,7 @@ static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct, * passenden Typ verzweigt und die relevanten Variablen weitergegeben. */ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, - float vigour, int duration, float effect, int men) + double vigour, int duration, double effect, int men) { curse *c; @@ -785,7 +783,7 @@ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, * die Kraft des Curse um die halbe Stärke der Antimagie reduziert. * Zurückgegeben wird der noch unverbrauchte Rest von force. */ -float destr_curse(curse * c, int cast_level, float force) +double destr_curse(curse * c, int cast_level, double force) { if (cast_level < c->vigour) { /* Zauber ist nicht stark genug */ double probability = 0.1 + (cast_level - c->vigour) * 0.2; @@ -793,7 +791,7 @@ float destr_curse(curse * c, int cast_level, float force) if (chance(probability)) { force -= c->vigour; if (c->type->change_vigour) { - c->type->change_vigour(c, -((float)cast_level + 1) / 2); + c->type->change_vigour(c, -(cast_level + 1) / 2); } else { c->vigour -= cast_level + 1 / 2; diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 4d6729374..212090281 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -194,9 +194,9 @@ extern "C" { const struct curse_type *type; /* Zeiger auf ein curse_type-struct */ int flags; /* WARNING: these are XORed with type->flags! */ int duration; /* Dauer der Verzauberung. Wird jede Runde vermindert */ - float vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */ + double vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */ struct unit *magician; /* Pointer auf den Magier, der den Spruch gewirkt hat */ - float effect; + double effect; variant data; /* pointer auf spezielle curse-unterstructs */ } curse; @@ -211,7 +211,7 @@ extern "C" { int mergeflags; struct message *(*curseinfo) (const void *, objtype_t, const struct curse *, int); - void(*change_vigour) (curse *, float); + void(*change_vigour) (curse *, double); int(*read) (struct storage * store, curse * c, void *target); int(*write) (struct storage * store, const struct curse * c, const void *target); @@ -238,7 +238,7 @@ extern "C" { */ curse *create_curse(struct unit *magician, struct attrib **ap, - const curse_type * ctype, float vigour, int duration, float ceffect, + const curse_type * ctype, double vigour, int duration, double ceffect, int men); /* Verzweigt automatisch zum passenden struct-typ. Sollte es schon * einen Zauber dieses Typs geben, so wird der neue dazuaddiert. Die @@ -260,10 +260,10 @@ extern "C" { * gesetzt. Gibt immer den ersten Treffer von ap aus zurück. */ int curse_geteffect_int(const struct curse *c); - float curse_geteffect(const struct curse *c); + double curse_geteffect(const struct curse *c); /* verändert die Stärke der Verzauberung um i */ - float curse_changevigour(struct attrib **ap, curse * c, float i); + double curse_changevigour(struct attrib **ap, curse * c, double delta); /* gibt bei Personenbeschränkten Verzauberungen die Anzahl der * betroffenen Personen zurück. Ansonsten wird 0 zurückgegeben. */ @@ -297,7 +297,7 @@ extern "C" { void curse_done(struct attrib *a); int curse_age(struct attrib *a); - float destr_curse(struct curse *c, int cast_level, float force); + double destr_curse(struct curse *c, int cast_level, double force); int resolve_curse(variant data, void *address); bool is_cursed_with(const struct attrib *ap, const struct curse *c); diff --git a/src/kernel/region.c b/src/kernel/region.c index 807fb3d76..9f1ff1eeb 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -537,11 +537,12 @@ attrib_type at_travelunit = { NO_READ }; -void rsetroad(region * r, direction_t d, short val) +void rsetroad(region * r, direction_t d, int val) { connection *b; region *r2 = rconnect(r, d); + assert(val>=SHRT_MIN && val<=SHRT_MAX); if (!r2) { return; } @@ -561,7 +562,7 @@ void rsetroad(region * r, direction_t d, short val) } } -short rroad(const region * r, direction_t d) +int rroad(const region * r, direction_t d) { connection *b; region *r2 = rconnect(r, d); diff --git a/src/kernel/region.h b/src/kernel/region.h index b9558427a..5c2c3a17c 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -187,8 +187,8 @@ extern "C" { void setluxuries(struct region *r, const struct luxury_type *sale); int get_maxluxuries(void); - short rroad(const struct region *r, direction_t d); - void rsetroad(struct region *r, direction_t d, short value); + int rroad(const struct region *r, direction_t d); + void rsetroad(struct region *r, direction_t d, int value); bool is_coastregion(struct region *r); diff --git a/src/laws.c b/src/laws.c index 00553cde5..ed9bc2108 100755 --- a/src/laws.c +++ b/src/laws.c @@ -98,7 +98,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* chance that a peasant dies of starvation: */ -#define PEASANT_STARVATION_CHANCE 0.9F +#define PEASANT_STARVATION_CHANCE 0.9 /* Pferdevermehrung */ #define HORSEGROWTH 4 /* Wanderungschance pro Pferd */ @@ -257,7 +257,7 @@ static void calculate_emigration(region * r) } -static float peasant_growth_factor(void) +static double peasant_growth_factor(void) { return get_param_flt(global.parameters, "rules.peasants.growth.factor", 0.0001F * PEASANTGROWTH); } @@ -265,7 +265,7 @@ static float peasant_growth_factor(void) #ifdef SLOWLUCK int peasant_luck_effect(int peasants, int luck, int maxp, double variance) { int n, births=0; - float factor = peasant_growth_factor(); + double factor = peasant_growth_factor(); for (n = peasants; n && luck; --n) { int chances = 0; @@ -287,7 +287,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance) { return births; } #else -static float peasant_luck_factor(void) +static double peasant_luck_factor(void) { return get_param_flt(global.parameters, "rules.peasants.peasantluck.factor", PEASANTLUCK); } @@ -296,12 +296,10 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance) { int births = 0; double mean; - if (luck == 0) return 0; - mean = _min(luck, peasants) * peasant_luck_factor() - * peasant_growth_factor() * ((peasants / (double)maxp < .9) ? 1 : - PEASANTFORCE); + mean = peasant_luck_factor() * peasant_growth_factor() * _min(luck, peasants); + mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE); births = RAND_ROUND(normalvariate(mean, variance * mean)); if (births <= 0) @@ -349,7 +347,7 @@ static void peasants(region * r) /* Es verhungert maximal die unterernährten Bevölkerung. */ n = _min(peasants - satiated, rpeasants(r)); - dead += (int)(0.5F + n * PEASANT_STARVATION_CHANCE); + dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE); if (dead > 0) { message *msg = add_message(&r->msgs, msg_message("phunger", "dead", dead)); @@ -433,7 +431,7 @@ static void horses(region * r) horses = rhorses(r); if (horses > 0) { if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) { - rsethorses(r, (int)(horses * 0.9F)); + rsethorses(r, (int)(horses * 0.9)); } else if (maxhorses) { int i; @@ -445,7 +443,7 @@ static void horses(region * r) if (a_find(r->attribs, &at_horseluck)) growth *= 2; /* printf("Horses: <%d> %d -> ", growth, horses); */ - i = (int)(0.5F + (horses * 0.0001F) * growth); + i = (int)(0.5 + (horses * 0.0001) * growth); /* printf("%d\n", horses); */ rsethorses(r, horses + i); } @@ -2281,7 +2279,7 @@ static bool display_race(faction * f, unit * u, const race * rc) int a, at_count; char buf[2048], *bufp = buf; size_t size = sizeof(buf) - 1; - int bytes; + size_t bytes; if (u && u_race(u) != rc) return false; @@ -2297,7 +2295,7 @@ static bool display_race(faction * f, unit * u, const race * rc) info = LOC(f->locale, mkname("raceinfo", "no_info")); } - bytes = (int)strlcpy(bufp, info, size); + bytes = strlcpy(bufp, info, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -2345,28 +2343,28 @@ static bool display_race(faction * f, unit * u, const race * rc) } } if (rc->battle_flags & BF_EQUIPMENT) { - bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment")); + bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_PIERCE) { - bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce")); + bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_CUT) { - bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut")); + bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_BASH) { - bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash")); + bytes = (size_t)_snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } bytes = - _snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, + (size_t)_snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -2374,21 +2372,21 @@ static bool display_race(faction * f, unit * u, const race * rc) for (a = 0; a < RACE_ATTACKS; a++) { if (rc->attack[a].type != AT_NONE) { if (a != 0) - bytes = (int)strlcpy(bufp, ", ", size); + bytes = strlcpy(bufp, ", ", size); else - bytes = (int)strlcpy(bufp, ": ", size); + bytes = strlcpy(bufp, ": ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); switch (rc->attack[a].type) { case AT_STANDARD: bytes = - _snprintf(bufp, size, "%s (%s)", + (size_t)_snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_standard"), rc->def_damage); break; case AT_NATURAL: bytes = - _snprintf(bufp, size, "%s (%s)", + (size_t)_snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); break; case AT_SPELL: @@ -2396,11 +2394,11 @@ static bool display_race(faction * f, unit * u, const race * rc) case AT_DRAIN_ST: case AT_DRAIN_EXP: case AT_DAZZLE: - bytes = _snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); + bytes = (size_t)_snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); break; case AT_STRUCTURAL: bytes = - _snprintf(bufp, size, "%s (%s)", + (size_t)_snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); break; default: @@ -3130,7 +3128,7 @@ static building *age_building(building * b) else if (mage != NULL) { int sk = effskill(mage, SK_MAGIC); c->duration = _max(c->duration, sk / 2); - c->vigour = _max(c->vigour, sk); + c->vigour = _max(c->vigour, (float)sk); } } } diff --git a/src/magic.c b/src/magic.c index 72fe72a25..dd494445c 100644 --- a/src/magic.c +++ b/src/magic.c @@ -117,12 +117,12 @@ static float MagicRegeneration(void) return value; } -float MagicPower(void) +double MagicPower(void) { - static float value = -1.0; + static double value = -1.0; if (value < 0) { const char *str = get_param(global.parameters, "magic.power"); - value = str ? (float)atof(str) : 1.0f; + value = str ? atof(str) : 1.0; } return value; } @@ -1012,7 +1012,7 @@ float spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order *ord) { curse *c; - float force = (float)cast_level; + double force = cast_level; int elf_power; const struct resource_type *rtype; @@ -1041,7 +1041,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order if (curse_active(c)) { unit *mage = c->magician; force -= curse_geteffect(c); - curse_changevigour(&r->attribs, c, (float)-cast_level); + curse_changevigour(&r->attribs, c, -cast_level); cmistake(u, ord, 185, MSG_MAGIC); if (mage != NULL && mage->faction != NULL) { if (force > 0) { @@ -1340,7 +1340,7 @@ static void do_fumble(castorder * co) const spell *sp = co->sp; int level = co->level; int duration; - float effect; + double effect; ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell", u, r, sp)); @@ -1382,8 +1382,8 @@ static void do_fumble(castorder * co) case 2: /* temporary skill loss */ duration = _max(rng_int() % level / 2, 2); - effect = -(float)level / 2; - c = create_curse(u, &u->attribs, ct_find("skillmod"), (float)level, + effect = level / -2.0; + c = create_curse(u, &u->attribs, ct_find("skillmod"), level, duration, effect, 1); c->data.i = SK_MAGIC; ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); @@ -2067,7 +2067,7 @@ struct region * co_get_region(const struct castorder * co) { } castorder *create_castorder(castorder * co, unit *caster, unit * familiar, const spell * sp, region * r, - int lev, float force, int range, struct order * ord, spellparameter * p) + int lev, double force, int range, struct order * ord, spellparameter * p) { if (!co) co = (castorder*)calloc(1, sizeof(castorder)); diff --git a/src/magic.h b/src/magic.h index 1494b0170..280b209d3 100644 --- a/src/magic.h +++ b/src/magic.h @@ -291,7 +291,7 @@ extern "C" { struct castorder *create_castorder(struct castorder * co, struct unit *caster, struct unit * familiar, const struct spell * sp, struct region * r, - int lev, float force, int range, struct order * ord, struct spellparameter * p); + int lev, double force, int range, struct order * ord, struct spellparameter * p); void free_castorder(struct castorder *co); /* Zwischenspreicher für Zauberbefehle, notwendig für Prioritäten */ void add_castorder(struct spellrank *cll, struct castorder *co); @@ -360,7 +360,7 @@ extern "C" { extern void write_spells(struct quicklist *slist, struct storage *store); extern void read_spells(struct quicklist **slistp, magic_t mtype, struct storage *store); - extern float MagicPower(void); + extern double MagicPower(void); extern struct spellbook * get_spellbook(const char * name); extern void free_spellbooks(void); diff --git a/src/modules/score.c b/src/modules/score.c index 644a79f49..bf3e472e1 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -161,8 +161,8 @@ void score(void) if (f->num_total != 0) { fprintf(scoreFP, "%8d (%8d/%4.2f%%/%5.2f) %30.30s (%3.3s) %5s (%3d)\n", f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1), - ((float)f->score / (float)allscores) * 100.0, - (float)f->score / f->num_total, + ((double)f->score / allscores) * 100, + (double)f->score / f->num_total, f->name, LOC(default_locale, rc_name_s(f->race, NAME_SINGULAR)), factionid(f), f->age); } diff --git a/src/randenc.c b/src/randenc.c index 0a6042eec..3c7988a20 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -1189,7 +1189,7 @@ void plagues(region * r) int dead = 0; peasants = rpeasants(r); - dead = (int)(0.5F + PLAGUE_VICTIMS * peasants); + dead = (int)(0.5 + PLAGUE_VICTIMS * peasants); for (i = dead; i != 0; i--) { if (rng_double() < PLAGUE_HEALCHANCE && rmoney(r) >= PLAGUE_HEALCOST) { rsetmoney(r, rmoney(r) - PLAGUE_HEALCOST); diff --git a/src/randenc.h b/src/randenc.h index 1f8ecf739..cc799db5f 100644 --- a/src/randenc.h +++ b/src/randenc.h @@ -25,9 +25,9 @@ extern "C" { struct region; /** Plagues **/ -#define PLAGUE_CHANCE 0.1F /* Seuchenwahrscheinlichkeit (siehe plagues()) */ -#define PLAGUE_VICTIMS 0.2F /* % Betroffene */ -#define PLAGUE_HEALCHANCE 0.25F /* Wahrscheinlichkeit Heilung */ +#define PLAGUE_CHANCE 0.1 /* Seuchenwahrscheinlichkeit (siehe plagues()) */ +#define PLAGUE_VICTIMS 0.2 /* % Betroffene */ +#define PLAGUE_HEALCHANCE 0.25 /* Wahrscheinlichkeit Heilung */ #define PLAGUE_HEALCOST 30 /* Heilkosten */ void plagues(struct region *r); void encounters(void); diff --git a/src/spells.c b/src/spells.c index 5905d4119..b13ed5e3e 100644 --- a/src/spells.c +++ b/src/spells.c @@ -298,7 +298,7 @@ static void magicanalyse_ship(ship * sh, unit * mage, double force) } -static int break_curse(attrib ** alist, int cast_level, float force, curse * c) +static int break_curse(attrib ** alist, int cast_level, double force, curse * c) { int succ = 0; /* attrib **a = a_find(*ap, &at_curse); */ @@ -327,7 +327,7 @@ static int break_curse(attrib ** alist, int cast_level, float force, curse * c) * auf alle Verzauberungen wirken. Ansonsten pruefe, ob der Curse vom * richtigen Typ ist. */ if (!c || c == c1) { - float remain = destr_curse(c1, cast_level, force); + double remain = destr_curse(c1, cast_level, force); if (remain < force) { succ = cast_level; force = remain; From df325b243aa6b329be00206f54e06986e18fda7b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 May 2015 20:35:36 +0200 Subject: [PATCH 2/4] enable stricter conversion checking for gcc < 4.9, fix code --- src/CMakeLists.txt | 3 +- src/battle.c | 6 +- src/bindings.c | 2 +- src/creport.c | 2 +- src/gmtool.c | 4 +- src/kernel/equipment.c | 4 +- src/kernel/order.c | 13 ++- src/kernel/order.h | 2 +- src/kernel/region.c | 4 +- src/magic.c | 2 +- src/magic.h | 4 +- src/reports.test.c | 4 +- src/spells.c | 164 ++++++++++++++++++------------------- src/spells/borders.c | 2 +- src/spells/combatspells.c | 4 +- src/spells/shipcurse.c | 4 +- src/spells/shipcurse.h | 4 +- src/triggers/createcurse.c | 13 +-- src/triggers/createcurse.h | 4 +- src/util/bsdstring.test.c | 16 ++-- src/util/goodies.h | 27 +----- src/util/strings.c | 2 +- src/util/strings.test.c | 2 +- src/util/unicode.c | 2 +- 24 files changed, 137 insertions(+), 157 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79bb02531..a37de77c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,8 +16,9 @@ if (CMAKE_COMPILER_IS_GNUCC) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if (GCC_VERSION VERSION_GREATER 4.9) - message(STATUS "Version ${GCC_VERSION} >= 4.9") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion") + else() + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") endif() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") diff --git a/src/battle.c b/src/battle.c index 1ed7df3b0..ee9465602 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1695,7 +1695,7 @@ void do_combatmagic(battle * b, combatmagic_t was) level = eff_skill(mage, SK_MAGIC, r); if (level > 0) { - float power; + double power; const spell *sp; const struct locale *lang = mage->faction->locale; order *ord; @@ -2497,14 +2497,14 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype) static int loot_quota(const unit * src, const unit * dst, const item_type * type, int n) { - static float divisor = -1; + static double divisor = -1; if (dst && src && src->faction != dst->faction) { if (divisor < 0) { divisor = get_param_flt(global.parameters, "rules.items.loot_divisor", 1); assert(divisor == 0 || divisor >= 1); } if (divisor >= 1) { - double r = (float)n / divisor; + double r = n / divisor; int x = (int)r; r = r - x; diff --git a/src/bindings.c b/src/bindings.c index 169c91d0c..2b77e0562 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -118,7 +118,7 @@ static int tolua_quicklist_iter(lua_State * L) quicklist **qlp = (quicklist **)lua_touserdata(L, lua_upvalueindex(1)); quicklist *ql = *qlp; if (ql != NULL) { - int index = lua_tointeger(L, lua_upvalueindex(2)); + int index = (int)lua_tointeger(L, lua_upvalueindex(2)); const char *type = lua_tostring(L, lua_upvalueindex(3)); void *data = ql_get(ql, index); tolua_pushusertype(L, data, TOLUA_CAST type); diff --git a/src/creport.c b/src/creport.c index 97a9ca064..abe528a1d 100644 --- a/src/creport.c +++ b/src/creport.c @@ -62,7 +62,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include #include diff --git a/src/gmtool.c b/src/gmtool.c index fc9fccdb9..f8feb7091 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -77,7 +77,7 @@ static WINDOW *hstatus; static void init_curses(void) { - short fg, bg; + int fg, bg; initscr(); if (has_colors() || force_color) { @@ -93,7 +93,7 @@ static void init_curses(void) #endif for (fg = 0; fg != 8; ++fg) { for (bg = 0; bg != 2; ++bg) { - init_pair(fg + 8 * bg, fg, bg ? hcol : bcol); + init_pair((short)(fg + 8 * bg), (short)fg, (short)(bg ? hcol : bcol)); } } diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index e426f8e0f..1511e2865 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -174,7 +174,7 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) int i; for (i = 0; eq->subsets[i].sets; ++i) { if (chance(eq->subsets[i].chance)) { - float rnd = (1 + rng_int() % 1000) / 1000.0f; + double rnd = (1 + rng_int() % 1000) / 1000.0; int k; for (k = 0; eq->subsets[i].sets[k].set; ++k) { if (rnd <= eq->subsets[i].sets[k].chance) { @@ -209,7 +209,7 @@ void equip_items(struct item **items, const struct equipment *eq) int i; for (i = 0; eq->subsets[i].sets; ++i) { if (chance(eq->subsets[i].chance)) { - float rnd = (1 + rng_int() % 1000) / 1000.0f; + double rnd = (1 + rng_int() % 1000) / 1000.0; int k; for (k = 0; eq->subsets[i].sets[k].set; ++k) { if (rnd <= eq->subsets[i].sets[k].chance) { diff --git a/src/kernel/order.c b/src/kernel/order.c index fc29932fc..b72b8e6bd 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -249,7 +249,7 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex) return data; } -static order *create_order_i(keyword_t kwd, const char *sptr, int persistent, +static order *create_order_i(keyword_t kwd, const char *sptr, bool persistent, const struct locale *lang) { order *ord = NULL; @@ -338,7 +338,7 @@ order *create_order(keyword_t kwd, const struct locale * lang, else { zBuffer[0] = 0; } - return create_order_i(kwd, zBuffer, 0, lang); + return create_order_i(kwd, zBuffer, false, lang); } order *parse_order(const char *s, const struct locale * lang) @@ -351,11 +351,11 @@ order *parse_order(const char *s, const struct locale * lang) if (*s != 0) { keyword_t kwd; const char *sptr; - int persistent = 0; + bool persistent = false; const char * p; while (*s == '@') { - persistent = 1; + persistent = true; ++s; } sptr = s; @@ -511,18 +511,15 @@ bool is_long(const order * ord) bool is_persistent(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); - int persist = ord->_persistent != 0; switch (kwd) { case K_MOVE: case NOKEYWORD: /* lang, aber niemals persistent! */ return false; - case K_KOMMENTAR: return true; - default: - return persist || is_repeated(ord); + return ord->_persistent || is_repeated(ord); } } diff --git a/src/kernel/order.h b/src/kernel/order.h index 22e401438..27c61681c 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -33,7 +33,7 @@ extern "C" { struct order *next; /* do not access this data: */ struct order_data *data; - int _persistent : 1; + bool _persistent; } order; /* constructor */ diff --git a/src/kernel/region.c b/src/kernel/region.c index 9f1ff1eeb..b227394a8 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -555,10 +555,10 @@ void rsetroad(region * r, direction_t d, int val) b = new_border(&bt_road, r, r2); } if (r == b->from) { - b->data.sa[0] = val; + b->data.sa[0] = (short)val; } else { - b->data.sa[1] = val; + b->data.sa[1] = (short)val; } } diff --git a/src/magic.c b/src/magic.c index dd494445c..e50393d40 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1008,7 +1008,7 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord) * Spruchfunktionsroutine ermittelt. */ -float +double spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order *ord) { curse *c; diff --git a/src/magic.h b/src/magic.h index 280b209d3..13ca5d517 100644 --- a/src/magic.h +++ b/src/magic.h @@ -131,7 +131,7 @@ extern "C" { den Vertrauten gezaubert wird */ const struct spell *sp; /* Spruch */ int level; /* gewünschte Stufe oder Stufe des Magiers */ - float force; /* Stärke des Zaubers */ + double force; /* Stärke des Zaubers */ struct region *_rtarget; /* Zielregion des Spruchs */ int distance; /* Entfernung zur Zielregion */ struct order *order; /* Befehl */ @@ -277,7 +277,7 @@ extern "C" { /* verändert die maximalen Magiepunkte einer Einheit */ /* Zaubern */ - extern float spellpower(struct region *r, struct unit *u, const struct spell * sp, + extern double spellpower(struct region *r, struct unit *u, const struct spell * sp, int cast_level, struct order *ord); /* ermittelt die Stärke eines Spruchs */ bool fumble(struct region *r, struct unit *u, const struct spell * sp, diff --git a/src/reports.test.c b/src/reports.test.c index 3d9536ee1..eb772782f 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -71,12 +71,12 @@ static void test_regionid(CuTest * tc) { memset(buffer, 0x7d, sizeof(buffer)); len = f_regionid(r, 0, buffer, sizeof(buffer)); - CuAssertIntEquals(tc, 11, len); + CuAssertIntEquals(tc, 11, (int)len); CuAssertStrEquals(tc, "plain (0,0)", buffer); memset(buffer, 0x7d, sizeof(buffer)); len = f_regionid(r, 0, buffer, 11); - CuAssertIntEquals(tc, 10, len); + CuAssertIntEquals(tc, 10, (int)len); CuAssertStrEquals(tc, "plain (0,0", buffer); CuAssertIntEquals(tc, 0x7d, buffer[11]); } diff --git a/src/spells.c b/src/spells.c index b13ed5e3e..a2506439b 100644 --- a/src/spells.c +++ b/src/spells.c @@ -102,7 +102,7 @@ #include /* ----------------------------------------------------------------------- */ -static float zero_effect = 0.0F; +static double zero_effect = 0.0; attrib_type at_wdwpyramid = { "wdwpyramid", NULL, NULL, NULL, a_writevoid, a_readvoid @@ -636,7 +636,7 @@ static int sp_destroy_magic(castorder * co) { unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; curse *c = NULL; char ts[80]; @@ -801,7 +801,7 @@ static int sp_goodwinds(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; int duration = cast_level + 1; spellparameter *pa = co->par; message *m; @@ -898,7 +898,7 @@ static int sp_summonent(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; unit *u; attrib *a; int ents; @@ -1124,7 +1124,7 @@ static int sp_hain(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; if (!r->land) { cmistake(mage, co->order, 296, MSG_MAGIC); @@ -1170,7 +1170,7 @@ static int sp_mallornhain(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; if (!r->land) { cmistake(mage, co->order, 296, MSG_MAGIC); @@ -1204,7 +1204,7 @@ static void fumble_ents(const castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; /* int cast_level = co->level; */ - float force = co->force; + double force = co->force; if (!r->land) { cmistake(mage, co->order, 296, MSG_MAGIC); @@ -1368,10 +1368,10 @@ static int sp_kaelteschutz(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = _max(cast_level, (int)force) + 1; spellparameter *pa = co->par; - float effect; + double effect; force *= 10; /* 10 Personen pro Force-Punkt */ @@ -1431,7 +1431,7 @@ static int sp_sparkle(castorder * co) int cast_level = co->level; spellparameter *pa = co->par; int duration = cast_level + 1; - float effect; + double effect; /* wenn kein Ziel gefunden, Zauber abbrechen */ if (pa->param[0]->flag == TARGET_NOTFOUND) @@ -1491,7 +1491,7 @@ static int sp_create_irongolem(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int number = lovar(force * 8 * RESOURCE_QUANTITY); if (number < 1) number = 1; @@ -1616,9 +1616,9 @@ static int sp_great_drought(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = 2; - float effect; + double effect; if (fval(r->terrain, SEA_REGION)) { cmistake(mage, co->order, 189, MSG_MAGIC); @@ -1743,7 +1743,7 @@ static int sp_treewalkenter(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; spellparameter *pa = co->par; - float power = co->force; + double power = co->force; int cast_level = co->level; region *rt; int remaining_cap; @@ -1868,7 +1868,7 @@ static int sp_treewalkexit(castorder * co) int erfolg = 0; region *r = co_get_region(co); unit *mage = co->magician.u; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; int cast_level = co->level; @@ -2007,7 +2007,7 @@ static int sp_holyground(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; message *msg = msg_message("sp_holyground_effect", "mage region", mage, r); report_spell(mage, r, msg); msg_release(msg); @@ -2042,8 +2042,8 @@ static int sp_homestone(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; - float effect; + double force = co->force; + double effect; message *msg; if (!mage->building || mage->building->type != bt_find("castle")) { cmistake(mage, co->order, 197, MSG_MAGIC); @@ -2101,7 +2101,7 @@ static int sp_drought(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; int duration = (int)power + 1; message *msg; @@ -2126,7 +2126,7 @@ static int sp_drought(castorder * co) c->duration = _max(c->duration, (int)power); } else { - float effect = 4.0; + double effect = 4.0; /* Baeume und Pferde sterben */ rsettrees(r, 2, rtrees(r, 2) / 2); rsettrees(r, 1, rtrees(r, 1) / 2); @@ -2222,7 +2222,7 @@ static int sp_stormwinds(castorder * co) int erfolg = 0; region *r = co_get_region(co); unit *mage = co->magician.u; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; int n, force = (int)power; message *m = NULL; @@ -2502,8 +2502,8 @@ static int sp_fumblecurse(castorder * co) int duration; unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; - float effect; + double force = co->force; + double effect; curse *c; spellparameter *pa = co->par; @@ -2535,9 +2535,9 @@ void patzer_fumblecurse(const castorder * co) { unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (cast_level / 2) + 1; - float effect; + double effect; curse *c; effect = force / 2; @@ -2574,7 +2574,7 @@ static int sp_summondragon(castorder * co) unit *mage = co->magician.u; unit *u; int cast_level = co->level; - float power = co->force; + double power = co->force; region_list *rl, *rl2; faction *f; int time; @@ -2646,7 +2646,7 @@ static int sp_firewall(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; direction_t dir; region *r2; @@ -2843,9 +2843,9 @@ static struct curse_type ct_deathcloud = { NULL, dc_age }; -static curse *mk_deathcloud(unit * mage, region * r, float force, int duration) +static curse *mk_deathcloud(unit * mage, region * r, double force, int duration) { - float effect; + double effect; curse *c; effect = force / 2; @@ -2878,7 +2878,7 @@ static int dc_read_compat(struct attrib *a, void *target, struct storage * store r = findregion(rx, ry); if (r != NULL) { - float effect; + double effect; curse *c; effect = strength; @@ -3024,7 +3024,7 @@ static int sp_summonshadow(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; unit *u; int val, number = (int)(force * force); @@ -3065,7 +3065,7 @@ static int sp_summonshadowlords(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int amount = (int)(force * force); u = create_unit(r, mage->faction, amount, get_race(RC_SHADOWLORD), 0, @@ -3192,8 +3192,8 @@ static int sp_magicboost(castorder * co) curse *c; unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; - float effect; + double power = co->force; + double effect; trigger *tsummon; static const curse_type *ct_auraboost; static const curse_type *ct_magicboost; @@ -3425,7 +3425,7 @@ static int sp_analysesong_obj(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; obj = pa->param[0]->typ; @@ -3474,7 +3474,7 @@ static int sp_analysesong_unit(castorder * co) unit *u; unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -3559,7 +3559,7 @@ static int sp_charmingsong(castorder * co) skill_t i; unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; int resist_bonus = 0; int tb = 0; @@ -3648,7 +3648,7 @@ static int sp_song_resistmagic(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (int)force + 1; create_curse(mage, &r->attribs, ct_find("goodmagicresistancezone"), @@ -3677,7 +3677,7 @@ static int sp_song_susceptmagic(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (int)force + 1; create_curse(mage, &r->attribs, ct_find("badmagicresistancezone"), @@ -3759,7 +3759,7 @@ static int sp_raisepeasantmob(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (int)force + 1; faction *monsters = get_monsters(); message *msg; @@ -3883,7 +3883,7 @@ static int sp_song_of_peace(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = 2 + lovar(force / 2); message *msg[2] = { NULL, NULL }; @@ -3932,9 +3932,9 @@ static int sp_generous(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (int)force + 1; - float effect; + double effect; message *msg[2] = { NULL, NULL }; if (is_cursed(r->attribs, C_DEPRESSION, 0)) { @@ -3990,7 +3990,7 @@ static int sp_recruit(castorder * co) double n; unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; faction *f = mage->faction; const struct race *rc = f->race; @@ -4045,7 +4045,7 @@ static int sp_bigrecruit(castorder * co) int n, maxp = rpeasants(r); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; faction *f = mage->faction; message *msg; @@ -4168,7 +4168,7 @@ static int sp_seduce(castorder * co) unit *mage = co->magician.u; spellparameter *pa = co->par; int cast_level = co->level; - float force = co->force; + double force = co->force; /* wenn kein Ziel gefunden, Zauber abbrechen */ if (pa->param[0]->flag == TARGET_NOTFOUND) @@ -4244,8 +4244,8 @@ static int sp_calm_monster(castorder * co) unit *mage = co->magician.u; spellparameter *pa = co->par; int cast_level = co->level; - float force = co->force; - float effect; + double force = co->force; + double effect; message *msg; /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -4260,7 +4260,7 @@ static int sp_calm_monster(castorder * co) return 0; } - effect = (float)mage->faction->subscription; + effect = mage->faction->subscription; c = create_curse(mage, &target->attribs, ct_find("calmmonster"), force, (int)force, effect, 0); if (c == NULL) { @@ -4352,7 +4352,7 @@ static int sp_raisepeasants(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; message *msg; if (rpeasants(r) == 0) { @@ -4405,7 +4405,7 @@ static int sp_depression(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (int)force + 1; message *msg; @@ -4472,7 +4472,7 @@ int sp_icastle(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; icastle_data *data; const char *bname; @@ -4551,7 +4551,7 @@ int sp_illusionary_shapeshift(castorder * co) const race *rc; unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; const race *irace; @@ -4689,7 +4689,7 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) int duration; unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; region *r = co_get_region(co); curse *c; @@ -4699,7 +4699,7 @@ static int sp_gbdreams(castorder * co, const char *curse_name, int effect) duration = 2 + rng_int() % duration; /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ - c = create_curse(mage, &r->attribs, ct_find(curse_name), power, duration, (float)effect, 0); + c = create_curse(mage, &r->attribs, ct_find(curse_name), power, duration, effect, 0); /* Erfolg melden */ ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect", @@ -4759,7 +4759,7 @@ int sp_dreamreading(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; spellparameter *pa = co->par; - float power = co->force; + double power = co->force; message *msg; /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -4810,7 +4810,7 @@ int sp_sweetdreams(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; int men, n; int duration = (int)(power / 2) + 1; @@ -4820,7 +4820,7 @@ int sp_sweetdreams(castorder * co) for (n = 0; n < pa->length; n++) { curse *c; unit *u; - float effect; + double effect; message *msg; /* sollte nie negativ werden */ if (opfer < 1) @@ -4860,9 +4860,9 @@ int sp_disturbingdreams(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; int duration = 1 + (int)(power / 6); - float effect; + double effect; curse *c; effect = 10; @@ -4950,7 +4950,7 @@ int sp_itemcloak(castorder * co) unit *mage = co->magician.u; spellparameter *pa = co->par; int cast_level = co->level; - float power = co->force; + double power = co->force; int duration = (int)_max(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -4990,7 +4990,7 @@ int sp_resist_magic_bonus(castorder * co) int duration = 6; unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; /* Pro Stufe koennen bis zu 5 Personen verzaubert werden */ double maxvictims = 5 * power; @@ -5050,7 +5050,7 @@ int sp_enterastral(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; switch (getplaneid(r)) { @@ -5165,7 +5165,7 @@ int sp_pullastral(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; switch (getplaneid(r)) { @@ -5307,7 +5307,7 @@ int sp_leaveastral(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; switch (getplaneid(r)) { @@ -5434,7 +5434,7 @@ int sp_fetchastral(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; spellparameter *pa = co->par; - float power = co->force; + double power = co->force; int remaining_cap = (int)((power - 3) * 1500); region_list *rtl = NULL; region *rt = co_get_region(co); /* region to which we are fetching */ @@ -5566,7 +5566,7 @@ int sp_showastral(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; switch (getplaneid(r)) { case 0: @@ -5697,7 +5697,7 @@ int sp_disruptastral(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; int duration = (int)(power / 3) + 1; switch (getplaneid(r)) { @@ -5722,7 +5722,7 @@ int sp_disruptastral(castorder * co) for (rl2 = rl; rl2 != NULL; rl2 = rl2->next) { attrib *a; - float effect; + double effect; region *r2 = rl2->data; spec_direction *sd; int inhab_regions = 0; @@ -5806,7 +5806,7 @@ static int sp_eternizewall(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; message *msg; @@ -6011,7 +6011,7 @@ int sp_flying_ship(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; message *m = NULL; int cno; @@ -6078,7 +6078,7 @@ int sp_stealaura(castorder * co) unit *u; unit *mage = co->magician.u; int cast_level = co->level; - float power = co->force; + double power = co->force; spellparameter *pa = co->par; /* wenn kein Ziel gefunden, Zauber abbrechen */ @@ -6143,12 +6143,12 @@ int sp_stealaura(castorder * co) */ int sp_antimagiczone(castorder * co) { - float power; - float effect; + double power; + double effect; region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; int duration = (int)force + 1; /* Haelt Sprueche bis zu einem summierten Gesamtlevel von power aus. @@ -6157,7 +6157,7 @@ int sp_antimagiczone(castorder * co) power = force * 10; /* Reduziert die Staerke jedes Spruchs um effect */ - effect = (float)cast_level; + effect = cast_level; create_curse(mage, &r->attribs, ct_find("antimagiczone"), power, duration, effect, 0); @@ -6205,9 +6205,9 @@ static int sp_magicrunes(castorder * co) int duration; unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; - float effect; + double effect; duration = 3 + rng_int() % cast_level; effect = 20; @@ -6265,14 +6265,14 @@ int sp_speed2(castorder * co) unit *u; unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; maxmen = 2 * cast_level * cast_level; dur = _max(1, cast_level / 2); for (n = 0; n < pa->length; n++) { - float effect; + double effect; /* sollte nie negativ werden */ if (maxmen < 1) break; @@ -6326,7 +6326,7 @@ int sp_q_antimagie(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; const char *ts = NULL; @@ -6406,7 +6406,7 @@ int sp_break_curse(castorder * co) region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; - float force = co->force; + double force = co->force; spellparameter *pa = co->par; const char *ts = NULL; diff --git a/src/spells/borders.c b/src/spells/borders.c index 5994e2b14..e3d29c152 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -86,7 +86,7 @@ static int cw_read(attrib * a, void *target, storage * store) * Was fuer eine Wirkung hat die? */ -void wall_vigour(curse * c, float delta) +void wall_vigour(curse * c, double delta) { wallcurse *wc = (wallcurse *)c->data.v; assert(wc->buddy->vigour == c->vigour); diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 77436f563..cbbafbfbc 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -908,11 +908,11 @@ int sp_strong_wall(struct castorder * co) { fighter * fi = co->magician.fig; int level = co->level; - float power = co->force; + double power = co->force; battle *b = fi->side->battle; unit *mage = fi->unit; building *burg; - float effect; + double effect; static bool init = false; message *msg; static const curse_type *strongwall_ct; diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index e79990fd6..29e4ad8f8 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -121,7 +121,7 @@ static struct curse_type ct_shipspeedup = { "shipspeedup", CURSETYP_NORM, 0, 0, cinfo_ship }; -curse *shipcurse_flyingship(ship * sh, unit * mage, float power, int duration) +curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration) { static const curse_type *ct_flyingship = NULL; if (!ct_flyingship) { @@ -146,7 +146,7 @@ curse *shipcurse_flyingship(ship * sh, unit * mage, float power, int duration) } } -int levitate_ship(ship * sh, unit * mage, float power, int duration) +int levitate_ship(ship * sh, unit * mage, double power, int duration) { curse *c = shipcurse_flyingship(sh, mage, power, duration); if (c) { diff --git a/src/spells/shipcurse.h b/src/spells/shipcurse.h index b64b3fd79..676cd7344 100644 --- a/src/spells/shipcurse.h +++ b/src/spells/shipcurse.h @@ -29,8 +29,8 @@ extern "C" { const struct curse *c, int self); void register_shipcurse(void); struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, - float power, int duration); - int levitate_ship(struct ship *sh, struct unit *mage, float power, + double power, int duration); + int levitate_ship(struct ship *sh, struct unit *mage, double power, int duration); #ifdef __cplusplus diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index eeff5eb51..07e8a370e 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -48,9 +48,9 @@ typedef struct createcurse_data { struct unit *mage; struct unit *target; const curse_type *type; - float vigour; + double vigour; int duration; - float effect; + double effect; int men; } createcurse_data; @@ -97,13 +97,15 @@ static int createcurse_read(trigger * t, struct storage *store) { createcurse_data *td = (createcurse_data *)t->data.v; char zText[128]; + float flt; read_reference(&td->mage, store, read_unit_reference, resolve_unit); read_reference(&td->target, store, read_unit_reference, resolve_unit); READ_TOK(store, zText, sizeof(zText)); td->type = ct_find(zText); - READ_FLT(store, &td->vigour); + READ_FLT(store, &flt); + td->vigour = flt; READ_INT(store, &td->duration); if (global.data_version < CURSEFLOAT_VERSION) { int n; @@ -111,7 +113,8 @@ static int createcurse_read(trigger * t, struct storage *store) td->effect = (float)n; } else { - READ_FLT(store, &td->effect); + READ_FLT(store, &flt); + td->effect = flt; } READ_INT(store, &td->men); return AT_READ_OK; @@ -127,7 +130,7 @@ trigger_type tt_createcurse = { }; trigger *trigger_createcurse(struct unit * mage, struct unit * target, - const curse_type * ct, float vigour, int duration, float effect, int men) + const curse_type * ct, double vigour, int duration, double effect, int men) { trigger *t = t_new(&tt_createcurse); createcurse_data *td = (createcurse_data *)t->data.v; diff --git a/src/triggers/createcurse.h b/src/triggers/createcurse.h index 9798e753a..c3602ec6a 100644 --- a/src/triggers/createcurse.h +++ b/src/triggers/createcurse.h @@ -33,8 +33,8 @@ extern "C" { extern struct trigger_type tt_createcurse; struct trigger *trigger_createcurse(struct unit *mage, - struct unit *target, const struct curse_type *ct, float vigour, - int duration, float effect, int men); + struct unit *target, const struct curse_type *ct, double vigour, + int duration, double effect, int men); #ifdef __cplusplus } diff --git a/src/util/bsdstring.test.c b/src/util/bsdstring.test.c index f7ac97dd3..6fcb86515 100644 --- a/src/util/bsdstring.test.c +++ b/src/util/bsdstring.test.c @@ -9,15 +9,15 @@ static void test_strlcat(CuTest * tc) memset(buffer, 0x7f, sizeof(buffer)); buffer[0] = '\0'; - CuAssertIntEquals(tc, 4, strlcat(buffer, "herp", 4)); + CuAssertIntEquals(tc, 4, (int)strlcat(buffer, "herp", 4)); CuAssertStrEquals(tc, "her", buffer); buffer[0] = '\0'; - CuAssertIntEquals(tc, 4, strlcat(buffer, "herp", 8)); + CuAssertIntEquals(tc, 4, (int)strlcat(buffer, "herp", 8)); CuAssertStrEquals(tc, "herp", buffer); CuAssertIntEquals(tc, 0x7f, buffer[5]); - CuAssertIntEquals(tc, 8, strlcat(buffer, "derp", 8)); + CuAssertIntEquals(tc, 8, (int)strlcat(buffer, "derp", 8)); CuAssertStrEquals(tc, "herpder", buffer); CuAssertIntEquals(tc, 0x7f, buffer[8]); } @@ -28,14 +28,14 @@ static void test_strlcpy(CuTest * tc) memset(buffer, 0x7f, sizeof(buffer)); - CuAssertIntEquals(tc, 4, strlcpy(buffer, "herp", 4)); + CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 4)); CuAssertStrEquals(tc, "her", buffer); - CuAssertIntEquals(tc, 4, strlcpy(buffer, "herp", 8)); + CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 8)); CuAssertStrEquals(tc, "herp", buffer); CuAssertIntEquals(tc, 0x7f, buffer[5]); - CuAssertIntEquals(tc, 8, strlcpy(buffer, "herpderp", 8)); + CuAssertIntEquals(tc, 8, (int)strlcpy(buffer, "herpderp", 8)); CuAssertStrEquals(tc, "herpder", buffer); CuAssertIntEquals(tc, 0x7f, buffer[8]); } @@ -49,11 +49,11 @@ static void test_slprintf(CuTest * tc) CuAssertTrue(tc, slprintf(buffer, 4, "%s", "herpderp") > 3); CuAssertStrEquals(tc, "her", buffer); - CuAssertIntEquals(tc, 4, slprintf(buffer, 8, "%s", "herp")); + CuAssertIntEquals(tc, 4, (int)slprintf(buffer, 8, "%s", "herp")); CuAssertStrEquals(tc, "herp", buffer); CuAssertIntEquals(tc, 0x7f, buffer[5]); - CuAssertIntEquals(tc, 8, slprintf(buffer, 8, "%s", "herpderp")); + CuAssertIntEquals(tc, 8, (int)slprintf(buffer, 8, "%s", "herpderp")); CuAssertStrEquals(tc, "herpder", buffer); CuAssertIntEquals(tc, 0x7f, buffer[8]); } diff --git a/src/util/goodies.h b/src/util/goodies.h index 045a23019..da18b2b36 100644 --- a/src/util/goodies.h +++ b/src/util/goodies.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef GOODIES_H #define GOODIES_H + +#include "strings.h" + #ifdef __cplusplus extern "C" { #endif @@ -29,30 +32,6 @@ extern "C" { extern int *intlist_add(int *i_p, int i); extern int *intlist_find(int *i_p, int i); - extern unsigned int hashstring(const char *s); - extern const char *escape_string(const char *str, char *buffer, - unsigned int len); - extern unsigned int jenkins_hash(unsigned int a); - extern unsigned int wang_hash(unsigned int a); - - /* benchmark for units: - * JENKINS_HASH: 5.25 misses/hit (with good cache behavior) - * WANG_HASH: 5.33 misses/hit (with good cache behavior) - * KNUTH_HASH: 1.93 misses/hit (with bad cache behavior) - * CF_HASH: fucking awful! - */ -#define KNUTH_HASH1(a, m) ((a) % m) -#define KNUTH_HASH2(a, m) (m - 2 - a % (m-2)) -#define CF_HASH1(a, m) ((a) % m) -#define CF_HASH2(a, m) (8 - ((a) & 7)) -#define JENKINS_HASH1(a, m) (jenkins_hash(a) % m) -#define JENKINS_HASH2(a, m) 1 -#define WANG_HASH1(a, m) (wang_hash(a) % m) -#define WANG_HASH2(a, m) 1 - -#define HASH1 JENKINS_HASH1 -#define HASH2 JENKINS_HASH2 - #ifdef __cplusplus } #endif diff --git a/src/util/strings.c b/src/util/strings.c index 948044532..7a3660ed5 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -32,7 +32,7 @@ unsigned int hashstring(const char *s) } const char *escape_string(const char *str, char *buffer, - unsigned int len) + size_t len) { const char *start = strchr(str, '\"'); if (!start) start = strchr(str, '\\'); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index c8dd63147..bcee29e47 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -2,7 +2,7 @@ #include #include #include -#include "goodies.h" +#include "strings.h" static void test_escape_string(CuTest * tc) { diff --git a/src/util/unicode.c b/src/util/unicode.c index 2a369ae1e..4be39a551 100644 --- a/src/util/unicode.c +++ b/src/util/unicode.c @@ -84,7 +84,7 @@ size_t * inlen) if (op - out >= os - 1) break; *op++ = 0xC3; - *op++ = c - 64; + *op++ = (unsigned char)(c - 64); } else if (c > 0x7F) { if (op - out >= os - 1) From 9d7a9cbe6a1f50602433ee50261f8f03a231243c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 May 2015 20:47:27 +0200 Subject: [PATCH 3/4] add missing new header --- src/util/strings.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/util/strings.h diff --git a/src/util/strings.h b/src/util/strings.h new file mode 100644 index 000000000..4157fc853 --- /dev/null +++ b/src/util/strings.h @@ -0,0 +1,52 @@ +/* +Copyright (c) 1998-2015, Enno Rehling +Katja Zedel + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#ifndef STRINGS_H +#define STRINGS_H +#ifdef __cplusplus +extern "C" { +#endif + + extern unsigned int hashstring(const char *s); + extern const char *escape_string(const char *str, char *buffer, + size_t len); + extern unsigned int jenkins_hash(unsigned int a); + extern unsigned int wang_hash(unsigned int a); + + /* benchmark for units: + * JENKINS_HASH: 5.25 misses/hit (with good cache behavior) + * WANG_HASH: 5.33 misses/hit (with good cache behavior) + * KNUTH_HASH: 1.93 misses/hit (with bad cache behavior) + * CF_HASH: fucking awful! + */ +#define KNUTH_HASH1(a, m) ((a) % m) +#define KNUTH_HASH2(a, m) (m - 2 - a % (m-2)) +#define CF_HASH1(a, m) ((a) % m) +#define CF_HASH2(a, m) (8 - ((a) & 7)) +#define JENKINS_HASH1(a, m) (jenkins_hash(a) % m) +#define JENKINS_HASH2(a, m) 1 +#define WANG_HASH1(a, m) (wang_hash(a) % m) +#define WANG_HASH2(a, m) 1 + +#define HASH1 JENKINS_HASH1 +#define HASH2 JENKINS_HASH2 + +#ifdef __cplusplus +} +#endif +#endif /* STRINGS_H */ From c4d14822505b56916418bde48f17a83c64126d02 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 May 2015 20:56:43 +0200 Subject: [PATCH 4/4] signed/unsigned comparisons (VC warning only) --- src/economy.c | 30 ++++++++++++++++-------------- src/report.c | 7 +++---- src/util/bsdstring.c | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/economy.c b/src/economy.c index 643ff1f0e..ec83bbc4e 100644 --- a/src/economy.c +++ b/src/economy.c @@ -79,7 +79,7 @@ typedef struct request { struct request *next; struct unit *unit; struct order *ord; - unsigned int qty; + int qty; int no; union { bool goblin; /* stealing */ @@ -91,7 +91,7 @@ static int working; static request entertainers[1024]; static request *nextentertainer; -static unsigned int entertaining; +static int entertaining; static unsigned int norders; static request *oa; @@ -1657,7 +1657,7 @@ static void expandbuying(region * r, request * buyorders) int multi; } trades[MAXLUXURIES], *trade; static int ntrades = 0; - int i, j; + int i; const luxury_type *ltype; if (ntrades == 0) { @@ -1686,6 +1686,7 @@ static void expandbuying(region * r, request * buyorders) * Güter pro Monat ist. j sind die Befehle, i der Index des * gehandelten Produktes. */ if (max_products > 0) { + unsigned int j; expandorders(r, buyorders); if (!norders) return; @@ -1884,7 +1885,8 @@ static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 }; static void expandselling(region * r, request * sellorders, int limit) { - int money, price, j, max_products; + int money, price, max_products; + unsigned int j; /* int m, n = 0; */ int maxsize = 0, maxeffsize = 0; int taxcollected = 0; @@ -2220,7 +2222,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) static void expandstealing(region * r, request * stealorders) { const resource_type *rsilver = get_resourcetype(R_SILVER); - int i; + unsigned int j; assert(rsilver); @@ -2233,8 +2235,8 @@ static void expandstealing(region * r, request * stealorders) * u ist die beklaute unit. oa.unit ist die klauende unit. */ - for (i = 0; i != norders && oa[i].unit->n <= oa[i].unit->wants; i++) { - unit *u = findunitg(oa[i].no, r); + for (j = 0; j != norders && oa[j].unit->n <= oa[j].unit->wants; j++) { + unit *u = findunitg(oa[j].no, r); int n = 0; if (u && u->region == r) { n = get_pooled(u, rsilver, GET_ALL, INT_MAX); @@ -2258,15 +2260,15 @@ static void expandstealing(region * r, request * stealorders) n = 10; } if (n > 0) { - n = _min(n, oa[i].unit->wants); + n = _min(n, oa[j].unit->wants); use_pooled(u, rsilver, GET_ALL, n); - oa[i].unit->n = n; - change_money(oa[i].unit, n); + oa[j].unit->n = n; + change_money(oa[j].unit, n); ADDMSG(&u->faction->msgs, msg_message("stealeffect", "unit region amount", u, u->region, n)); } - add_income(oa[i].unit, IC_STEAL, oa[i].unit->wants, oa[i].unit->n); - fset(oa[i].unit, UFL_LONGACTION | UFL_NOTMOVING); + add_income(oa[j].unit, IC_STEAL, oa[j].unit->wants, oa[j].unit->n); + fset(oa[j].unit, UFL_LONGACTION | UFL_NOTMOVING); } free(oa); } @@ -2909,7 +2911,7 @@ static int do_work(unit * u, order * ord, request * o) static void expandloot(region * r, request * lootorders) { unit *u; - int i; + unsigned int i; int looted = 0; int startmoney = rmoney(r); @@ -2946,7 +2948,7 @@ static void expandloot(region * r, request * lootorders) static void expandtax(region * r, request * taxorders) { unit *u; - int i; + unsigned int i; expandorders(r, taxorders); if (!norders) diff --git a/src/report.c b/src/report.c index a644e216f..fc3c3f54e 100644 --- a/src/report.c +++ b/src/report.c @@ -516,7 +516,7 @@ void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark) * mark, falls angegeben. SP wurde also auf 0 gesetzt vor dem Aufruf. * Vgl. spunit (). */ - int i, j, width; + unsigned int width; int firstline; static char buf[REPORTWIDTH + 1]; // FIXME: static return value @@ -524,10 +524,9 @@ void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark) firstline = 1; for (;;) { - i = 0; + unsigned int j = 0, i; - do { - j = i; + for (i=0; s[j]; j=i) { while (s[j] && s[j] != ' ') j++; if (j > width) { diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index 2cbf630d6..c43847da1 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -16,7 +16,7 @@ int wrptr(char **ptr, size_t * size, size_t bytes) *size = 0; return EINVAL; } - if (bytes <= *(int *)size) { + if (bytes <= *size) { *ptr += bytes; *size -= bytes; return 0;