Merge pull request #190 from badgerman/feature-warn-conversion

enable float-conversion warnings on gcc >= 4.9
This commit is contained in:
Enno Rehling 2015-05-15 18:20:46 +02:00
commit b14976683d
19 changed files with 211 additions and 181 deletions

View File

@ -12,11 +12,18 @@ include_directories (${LUA_INCLUDE_DIR})
include_directories (${BSON_INCLUDE_DIR})
include_directories (${INIPARSER_INCLUDE_DIR})
IF(CMAKE_COMPILER_IS_GNUCC)
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")
endif()
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} -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

View File

@ -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);
}
}
@ -2964,19 +2965,19 @@ static void print_header(battle * b)
side *s;
char *bufp = zText;
size_t size = sizeof(zText) - 1;
int bytes;
size_t bytes;
for (s = b->sides; s != b->sides + b->nsides; ++s) {
fighter *df;
for (df = s->fighters; df; df = df->next) {
if (is_attacker(df)) {
if (first) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
if (lastf) {
bytes = (int)strlcpy(bufp, (const char *)lastf, size);
bytes = strlcpy(bufp, (const char *)lastf, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
first = true;
@ -2990,18 +2991,18 @@ static void print_header(battle * b)
}
}
if (first) {
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, (const char *)LOC(f->locale, "and"), size);
bytes = strlcpy(bufp, (const char *)LOC(f->locale, "and"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
if (lastf) {
bytes = (int)strlcpy(bufp, (const char *)lastf, size);
bytes = strlcpy(bufp, (const char *)lastf, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -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)
@ -3715,7 +3717,7 @@ static int battle_report(battle * b)
faction *fac = bf->faction;
char buf[32 * MAXSIDES];
char *bufp = buf;
int bytes;
size_t bytes;
size_t size = sizeof(buf) - 1;
message *m;
@ -3738,32 +3740,32 @@ static int battle_report(battle * b)
char buffer[32];
if (komma) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
slprintf(buffer, sizeof(buffer), "%s %2d(%s): ",
loc_army, army_index(s), abbrev);
bytes = (int)strlcpy(bufp, buffer, size);
bytes = strlcpy(bufp, buffer, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
for (r = FIGHT_ROW; r != NUMROWS; ++r) {
if (alive[r]) {
if (l != FIGHT_ROW) {
bytes = (int)strlcpy(bufp, "+", size);
bytes = strlcpy(bufp, "+", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
while (k--) {
bytes = (int)strlcpy(bufp, "0+", size);
bytes = strlcpy(bufp, "0+", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
sprintf(buffer, "%d", alive[r]);
bytes = (int)strlcpy(bufp, buffer, size);
bytes = strlcpy(bufp, buffer, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();

View File

@ -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 */

View File

@ -1222,7 +1222,7 @@ cr_output_resources(FILE * F, report_context * ctx, seen_region * sr)
}
static void
cr_region_header(FILE * F, int plid, int nx, int ny, unsigned int uid)
cr_region_header(FILE * F, int plid, int nx, int ny, int uid)
{
if (plid == 0) {
fprintf(F, "REGION %d %d\n", nx, ny);

View File

@ -79,7 +79,7 @@ typedef struct request {
struct request *next;
struct unit *unit;
struct order *ord;
int qty;
unsigned int qty;
int no;
union {
bool goblin; /* stealing */
@ -91,9 +91,9 @@ static int working;
static request entertainers[1024];
static request *nextentertainer;
static int entertaining;
static unsigned int entertaining;
static int norders;
static unsigned int norders;
static request *oa;
#define RECRUIT_MERGE 1
@ -123,13 +123,13 @@ int income(const unit * u)
}
}
static void scramble(void *data, int n, size_t width)
static void scramble(void *data, unsigned int n, size_t width)
{
int j;
unsigned int j;
char temp[64];
assert(width <= sizeof(temp));
for (j = 0; j != n; ++j) {
int k = rng_int() % n;
unsigned int k = rng_uint() % n;
if (k == j)
continue;
memcpy(temp, (char *)data + j * width, width);
@ -162,7 +162,7 @@ static void expandorders(region * r, request * requests)
oa = (request *)calloc(norders, sizeof(request));
for (o = requests; o; o = o->next) {
if (o->qty > 0) {
int j;
unsigned int j;
for (j = o->qty; j; j--) {
oa[i] = *o;
oa[i].unit->n = 0;
@ -297,7 +297,7 @@ static int horse_recruiters(const struct race *rc, int qty)
if (rc->ec_flags & ECF_REC_ETHEREAL)
return -1;
if (rc->ec_flags & ECF_REC_HORSES)
return (int)(qty * 2 * rc->recruit_multi);
return (int)(qty * 2.0 * rc->recruit_multi);
return -1;
}
@ -354,7 +354,7 @@ static int do_recruiting(recruitment * recruits, int available)
unit *u = req->unit;
const race *rc = u_race(u); /* race is set in recruit() */
int number, dec;
float multi = 2.0F * rc->recruit_multi;
double multi = 2.0 * rc->recruit_multi;
number = _min(req->qty, (int)(get / multi));
if (rc->recruitcost) {
@ -463,7 +463,6 @@ static int recruit_cost(const faction * f, const race * rc)
static void recruit(unit * u, struct order *ord, request ** recruitorders)
{
int n;
region *r = u->region;
plane *pl;
request *o;
@ -471,9 +470,14 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
const faction *f = u->faction;
const struct race *rc = u_race(u);
const char *str;
int n;
init_order(ord);
n = getuint();
n = getint();
if (n<=0) {
syntax_error(u, ord);
return;
}
if (u->number == 0) {
char token[128];
@ -1784,8 +1788,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
kwd = init_order(ord);
assert(kwd == K_BUY);
n = getuint();
if (!n) {
n = getint();
if (n<=0) {
cmistake(u, ord, 26, MSG_COMMERCE);
return;
}
@ -2997,10 +3001,11 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
return;
}
max = getuint();
max = getint();
if (max == 0)
if (max <= 0) {
max = INT_MAX;
}
if (!playerrace(u_race(u))) {
u->wants = _min(income(u), max);
}
@ -3070,10 +3075,11 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders)
return;
}
max = getuint();
max = getint();
if (max == 0)
if (max <= 0) {
max = INT_MAX;
}
if (!playerrace(u_race(u))) {
u->wants = _min(income(u), max);
}

View File

@ -33,11 +33,11 @@ int json_import(struct stream * out) {
cJSON *j;
for (j = child->child; j; j = j->next) {
cJSON *attr;
unsigned int id = 0;
int id = 0;
int x = 0, y = 0;
region * r;
id = (unsigned int)atol(j->string);
id = atoi(j->string);
if ((attr = cJSON_GetObjectItem(j, "x")) != 0 && attr->type == cJSON_Number) x = attr->valueint;
if ((attr = cJSON_GetObjectItem(j, "y")) != 0 && attr->type == cJSON_Number) y = attr->valueint;
r = new_region(x, y, 0, id);

View File

@ -282,6 +282,14 @@ message * cmistake(const unit * u, struct order *ord, int mno, int mtype)
return result;
}
void syntax_error(const struct unit *u, struct order *ord)
{
message * result;
result = msg_error(u, ord, 10);
ADDMSG(&u->faction->msgs, result);
msg_release(result);
}
extern unsigned int new_hashstring(const char *s);
void free_messagelist(message_list * msgs)

View File

@ -56,6 +56,7 @@ extern "C" {
#define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } }
void syntax_error(const struct unit *u, struct order *ord);
struct message * cmistake(const struct unit *u, struct order *ord, int mno, int mtype);
struct message * msg_error(const struct unit * u, struct order *ord, int mno);
#ifdef __cplusplus

View File

@ -123,9 +123,9 @@ extern "C" {
struct param *parameters;
char *_name;
float magres;
float maxaura; /* Faktor auf Maximale Aura */
float regaura; /* Faktor auf Regeneration */
float recruit_multi; /* Faktor für Bauernverbrauch */
double maxaura; /* Faktor auf Maximale Aura */
double regaura; /* Faktor auf Regeneration */
double recruit_multi; /* Faktor für Bauernverbrauch */
int index;
int recruitcost;
int maintenance;

View File

@ -32,9 +32,9 @@ extern "C" {
unsigned int old:8;
#else
int id;
unsigned int level;
unsigned int weeks;
unsigned int old;
int level;
int weeks;
int old;
#endif
} skill;

View File

@ -984,7 +984,7 @@ static bool is_guardian_r(const unit * guard)
return true;
}
bool is_guard(const struct unit * u, int mask)
bool is_guard(const struct unit * u, unsigned int mask)
{
return is_guardian_r(u) && (getguard(u) & mask) != 0;
}
@ -1140,7 +1140,8 @@ static const char *shortdirections[MAXDIRECTIONS] = {
static void cycle_route(order * ord, unit * u, int gereist)
{
int bytes, cm = 0;
size_t bytes;
int cm = 0;
char tail[1024], *bufp = tail;
char neworder[2048];
char token[128];
@ -1180,11 +1181,11 @@ static void cycle_route(order * ord, unit * u, int gereist)
if (!pause) {
const char *loc = LOC(lang, shortdirections[d]);
if (bufp != tail) {
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
bytes = (int)strlcpy(bufp, loc, size);
bytes = strlcpy(bufp, loc, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -1193,10 +1194,10 @@ static void cycle_route(order * ord, unit * u, int gereist)
break;
else if (cm == gereist && !paused && pause) {
const char *loc = LOC(lang, parameters[P_PAUSE]);
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, loc, size);
bytes = strlcpy(bufp, loc, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
paused = true;
@ -1565,8 +1566,9 @@ static arg_regions *var_copy_regions(const region_list * begin, int size)
if (size > 0) {
int i = 0;
assert(size>0);
arg_regions *dst =
(arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * size);
(arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * (size_t)size);
dst->nregions = size;
dst->regions = (region **)(dst + 1);
for (rsrc = begin; i != size; rsrc = rsrc->next) {
@ -2536,7 +2538,8 @@ static direction_t hunted_dir(attrib * at, int id)
static int hunt(unit * u, order * ord)
{
region *rc = u->region;
int bytes, moves, id, speed;
size_t bytes;
int moves, id, speed;
char command[256], *bufp = command;
size_t size = sizeof(command);
direction_t dir;
@ -2581,7 +2584,7 @@ static int hunt(unit * u, order * ord)
moves = 1;
speed = getuint();
speed = (int)getuint();
if (speed == 0) {
speed = shipspeed(u->ship, u);
}
@ -2592,10 +2595,10 @@ static int hunt(unit * u, order * ord)
}
rc = rconnect(rc, dir);
while (moves < speed && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) {
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(u->faction->locale, directions[dir]), size);
bytes = strlcpy(bufp, LOC(u->faction->locale, directions[dir]), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
moves++;

View File

@ -60,7 +60,7 @@ extern "C" {
void movement(void);
void run_to(struct unit *u, struct region *to);
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
bool is_guard(const struct unit *u, int mask);
bool is_guard(const struct unit *u, unsigned int mask);
int enoughsailors(const struct ship *sh, const struct region *r);
bool canswim(struct unit *u);
bool canfly(struct unit *u);

View File

@ -509,7 +509,7 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang)
rnl(F);
}
void sparagraph(strlist ** SP, const char *s, int indent, char mark)
void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark)
{
/* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer

View File

@ -216,19 +216,19 @@ const char **name, const char **basename, int *number, bool singular)
static size_t buforder(char *bufp, size_t size, const order * ord, int mode)
{
size_t tsize = 0;
int bytes;
size_t bytes;
bytes = (int)strlcpy(bufp, ", \"", size);
bytes = strlcpy(bufp, ", \"", size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (mode < ORDERS_IN_NR) {
char cmd[ORDERSIZE];
get_command(ord, cmd, sizeof(cmd));
bytes = (int)strlcpy(bufp, cmd, size);
bytes = strlcpy(bufp, cmd, size);
}
else {
bytes = (int)strlcpy(bufp, "...", size);
bytes = strlcpy(bufp, "...", size);
}
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
@ -436,7 +436,7 @@ const faction * viewer)
}
int
bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
bufunit(const faction * f, const unit * u, unsigned int indent, int mode, char *buf,
size_t size)
{
int i, dh;
@ -452,7 +452,7 @@ size_t size)
char *bufp = buf;
bool itemcloak = false;
const curse_type *itemcloak_ct = 0;
int bytes;
size_t bytes;
item result[MAX_INVENTORY];
itemcloak_ct = ct_find("itemcloak");
@ -460,7 +460,7 @@ size_t size)
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
}
bytes = (int)strlcpy(bufp, unitname(u), size);
bytes = strlcpy(bufp, unitname(u), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -471,29 +471,29 @@ size_t size)
attrib *a = a_find(u->attribs, &at_group);
if (a) {
group *g = (group *)a->data.v;
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, groupid(g, f), size);
bytes = strlcpy(bufp, groupid(g, f), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
}
if (getarnt) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "anonymous"), size);
bytes = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else if (a_otherfaction) {
faction *otherfaction = get_otherfaction(a_otherfaction);
if (otherfaction) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, factionname(otherfaction), size);
bytes = strlcpy(bufp, factionname(otherfaction), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -501,10 +501,10 @@ size_t size)
}
else {
if (getarnt) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "anonymous"), size);
bytes = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -512,16 +512,16 @@ size_t size)
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
faction *f = get_otherfaction(a_otherfaction);
bytes =
_snprintf(bufp, size, ", %s (%s)", factionname(f),
(size_t)_snprintf(bufp, size, ", %s (%s)", factionname(f),
factionname(u->faction));
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, factionname(fv), size);
bytes = strlcpy(bufp, factionname(fv), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -529,30 +529,30 @@ size_t size)
}
}
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1
&& effskill(u, SK_STEALTH) >= 6) {
bytes = (int)strlcpy(bufp, "? ", size);
bytes = strlcpy(bufp, "? ", size);
}
else {
bytes = _snprintf(bufp, size, "%d ", u->number);
bytes = (size_t)_snprintf(bufp, size, "%d ", u->number);
}
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
pzTmp = get_racename(u->attribs);
if (pzTmp) {
bytes = (int)strlcpy(bufp, pzTmp, size);
bytes = strlcpy(bufp, pzTmp, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
bytes = (int)strlcpy(bufp, " (", size);
bytes = strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, racename(f->locale, u, u_race(u)), size);
bytes = strlcpy(bufp, racename(f->locale, u, u_race(u)), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (size > 1) {
@ -563,14 +563,14 @@ size_t size)
}
else {
const race *irace = u_irace(u);
bytes = (int)strlcpy(bufp, racename(f->locale, u, irace), size);
bytes = strlcpy(bufp, racename(f->locale, u, irace), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (u->faction == f && irace != u_race(u)) {
bytes = (int)strlcpy(bufp, " (", size);
bytes = strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, racename(f->locale, u, u_race(u)), size);
bytes = strlcpy(bufp, racename(f->locale, u, u_race(u)), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (size > 1) {
@ -581,10 +581,10 @@ size_t size)
}
if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "hero"), size);
bytes = strlcpy(bufp, LOC(f->locale, "hero"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -593,28 +593,28 @@ size_t size)
if (u->number && (u->faction == f || telepath_see || isbattle)) {
const char *c = hp_status(u);
c = c ? LOC(f->locale, c) : 0;
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, report_kampfstatus(u, f->locale), size);
bytes = strlcpy(bufp, report_kampfstatus(u, f->locale), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (c || fval(u, UFL_HUNGER)) {
bytes = (int)strlcpy(bufp, " (", size);
bytes = strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (c) {
bytes = (int)strlcpy(bufp, c, size);
bytes = strlcpy(bufp, c, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
if (fval(u, UFL_HUNGER)) {
if (c) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
bytes = (int)strlcpy(bufp, LOC(f->locale, "unit_hungers"), size);
bytes = strlcpy(bufp, LOC(f->locale, "unit_hungers"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -625,19 +625,19 @@ size_t size)
}
}
if (is_guard(u, GUARD_ALL) != 0) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, LOC(f->locale, "unit_guards"), size);
bytes = strlcpy(bufp, LOC(f->locale, "unit_guards"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
if ((b = usiege(u)) != NULL) {
bytes = (int)strlcpy(bufp, ", belagert ", size);
bytes = strlcpy(bufp, ", belagert ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, buildingname(b), size);
bytes = strlcpy(bufp, buildingname(b), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -646,7 +646,7 @@ size_t size)
if (u->faction == f || telepath_see) {
skill *sv;
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
bytes = (int)spskill(bufp, size, f->locale, u, sv, &dh, 1);
bytes = spskill(bufp, size, f->locale, u, sv, &dh, 1);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -670,25 +670,26 @@ size_t size)
}
for (itm = show; itm; itm = itm->next) {
const char *ic;
int in, bytes;
int in;
size_t bytes;
report_item(u, itm, f, &ic, NULL, &in, false);
if (in == 0 || ic == NULL)
continue;
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (!dh) {
bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory"));
bytes = (size_t)_snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory"));
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
dh = 1;
}
if (in == 1) {
bytes = (int)strlcpy(bufp, ic, size);
bytes = strlcpy(bufp, ic, size);
}
else {
bytes = _snprintf(bufp, size, "%d %s", in, ic);
bytes = (size_t)_snprintf(bufp, size, "%d %s", in, ic);
}
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -700,7 +701,7 @@ size_t size)
if (book) {
quicklist *ql = book->spells;
int qi, header, maxlevel = effskill(u, SK_MAGIC);
int bytes = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u));
size_t bytes = (size_t)_snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u));
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER();
}
@ -709,16 +710,16 @@ size_t size)
spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi);
if (sbe->level <= maxlevel) {
if (!header) {
bytes = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
bytes = (size_t)_snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
header = 1;
}
else {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
}
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER();
}
bytes = (int)strlcpy(bufp, spell_name(sbe->sp, f->locale), size);
bytes = strlcpy(bufp, spell_name(sbe->sp, f->locale), size);
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER();
}
@ -731,7 +732,7 @@ size_t size)
}
if (i != MAXCOMBATSPELLS) {
bytes =
_snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells"));
(size_t)_snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells"));
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -742,7 +743,7 @@ size_t size)
dh = 1;
}
else {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
if (bytes && wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER();
}
@ -750,20 +751,19 @@ size_t size)
sp = get_combatspell(u, i);
if (sp) {
int sl = get_combatspelllevel(u, i);
bytes =
(int)strlcpy(bufp, spell_name(sp, u->faction->locale), size);
bytes = strlcpy(bufp, spell_name(sp, u->faction->locale), size);
if (bytes && wrptr(&bufp, &size, bytes) != 0) {
WARN_STATIC_BUFFER();
}
if (sl > 0) {
bytes = _snprintf(bufp, size, " (%d)", sl);
bytes = (size_t)_snprintf(bufp, size, " (%d)", sl);
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
}
else {
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
bytes = strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
if (bytes && wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -776,7 +776,7 @@ size_t size)
for (ord = u->old_orders; ord; ord = ord->next) {
if (is_repeated(ord)) {
if (printed < ORDERS_IN_NR) {
bytes = (int)buforder(bufp, size, ord, printed++);
bytes = buforder(bufp, size, ord, printed++);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -788,7 +788,7 @@ size_t size)
for (ord = u->orders; ord; ord = ord->next) {
if (is_repeated(ord)) {
if (printed < ORDERS_IN_NR) {
bytes = (int)buforder(bufp, size, ord, printed++);
bytes = buforder(bufp, size, ord, printed++);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -802,11 +802,11 @@ size_t size)
str = u_description(u, f->locale);
if (str) {
bytes = (int)strlcpy(bufp, "; ", size);
bytes = strlcpy(bufp, "; ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, str, size);
bytes = strlcpy(bufp, str, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -820,13 +820,13 @@ size_t size)
}
pzTmp = uprivate(u);
if (u->faction == f && pzTmp) {
bytes = (int)strlcpy(bufp, " (Bem: ", size);
bytes = strlcpy(bufp, " (Bem: ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, pzTmp, size);
bytes = strlcpy(bufp, pzTmp, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, ")", size);
bytes = strlcpy(bufp, ")", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@ -854,7 +854,7 @@ const struct unit * u, struct skill * sv, int *dh, int days)
{
char *bufp = buffer;
int i, effsk;
int bytes;
size_t bytes;
size_t tsize = 0;
if (!u->number)
@ -865,30 +865,30 @@ const struct unit * u, struct skill * sv, int *dh, int days)
}
}
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (!*dh) {
bytes = (int)strlcpy(bufp, LOC(lang, "nr_skills"), size);
bytes = strlcpy(bufp, LOC(lang, "nr_skills"), size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, ": ", size);
bytes = strlcpy(bufp, ": ", size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
*dh = 1;
}
bytes = (int)strlcpy(bufp, skillname(sv->id, lang), size);
bytes = strlcpy(bufp, skillname(sv->id, lang), size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -897,13 +897,13 @@ const struct unit * u, struct skill * sv, int *dh, int days)
sc_mage *mage = get_mage(u);
if (mage && mage->magietyp != M_GRAY) {
bytes =
(int)strlcpy(bufp, LOC(lang, mkname("school",
strlcpy(bufp, LOC(lang, mkname("school",
magic_school[mage->magietyp])), size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, " ", size);
bytes = strlcpy(bufp, " ", size);
tsize += bytes;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -947,7 +947,7 @@ const struct unit * u, struct skill * sv, int *dh, int days)
return tsize;
}
void lparagraph(struct strlist **SP, char *s, int indent, char mark)
void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark)
{
/* Die Liste SP wird mit dem String s aufgefuellt, mit indent und einer
@ -967,7 +967,7 @@ void lparagraph(struct strlist **SP, char *s, int indent, char mark)
}
void
spunit(struct strlist **SP, const struct faction *f, const unit * u, int indent,
spunit(struct strlist **SP, const struct faction *f, const unit * u, unsigned int indent,
int mode)
{
char buf[DISPLAYSIZE];
@ -1705,7 +1705,7 @@ static seen_region **prepare_report(faction * f)
int write_reports(faction * f, time_t ltime)
{
int backup = 1, maxbackup = 128 * 1000;
unsigned int backup = 1, maxbackup = 128 * 1000;
bool gotit = false;
struct report_context ctx;
const char *encoding = "UTF-8";
@ -2279,7 +2279,7 @@ static void eval_resources(struct opstack **stack, const void *userdata)
while (res != NULL && size > 4) {
const char *rname =
resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0);
int bytes = _snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname));
size_t bytes = (size_t)_snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname));
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0 || size < sizeof(buf) / 2) {
WARN_STATIC_BUFFER();
break;
@ -2293,7 +2293,7 @@ static void eval_resources(struct opstack **stack, const void *userdata)
}
}
*bufp = 0;
var.v = strcpy(balloc(bufp - buf + 1), buf);
var.v = strcpy(balloc((size_t)(bufp - buf + 1)), buf);
opush(stack, var);
}
@ -2319,7 +2319,7 @@ static void eval_regions(struct opstack **stack, const void *userdata)
}
for (i = begin; i < end; ++i) {
const char *rname = (const char *)regionname(regions->regions[i], report);
int bytes = (int)strlcpy(bufp, rname, size);
size_t bytes = strlcpy(bufp, rname, size);
if (bytes && wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -2330,7 +2330,7 @@ static void eval_regions(struct opstack **stack, const void *userdata)
}
}
*bufp = 0;
var.v = strcpy(balloc(bufp - buf + 1), buf);
var.v = strcpy(balloc((size_t)(bufp - buf + 1)), buf);
opush(stack, var);
}
@ -2355,15 +2355,15 @@ static void eval_trail(struct opstack **stack, const void *userdata)
region *r = regions->regions[i];
const char *trail = trailinto(r, lang);
const char *rn = f_regionid_s(r, report);
int bytes = _snprintf(bufp, size, trail, rn);
size_t bytes = (size_t)_snprintf(bufp, size, trail, rn);
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (i + 2 < end) {
bytes = (int)strlcpy(bufp, ", ", size);
bytes = strlcpy(bufp, ", ", size);
}
else if (i + 1 < end) {
bytes = (int)strlcpy(bufp, LOC(lang, "list_and"), size);
bytes = strlcpy(bufp, LOC(lang, "list_and"), size);
}
else
bytes = 0;
@ -2373,7 +2373,7 @@ static void eval_trail(struct opstack **stack, const void *userdata)
}
}
*bufp = 0;
var.v = strcpy(balloc(bufp - buf + 1), buf);
var.v = strcpy(balloc((size_t)(bufp - buf +1)), buf);
opush(stack, var);
#ifdef _SECURECRT_ERRCODE_VALUES_DEFINED
if (errno == ERANGE) {

View File

@ -47,12 +47,12 @@ extern "C" {
struct unit *can_find(struct faction *, struct faction *);
/* funktionen zum schreiben eines reports */
void sparagraph(struct strlist **SP, const char *s, int indent, char mark);
void lparagraph(struct strlist **SP, char *s, int indent, char mark);
void sparagraph(struct strlist **SP, const char *s, unsigned int indent, char mark);
void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark);
const char *hp_status(const struct unit *u);
size_t spskill(char *pbuf, size_t siz, const struct locale *lang, const struct unit *u, struct skill *sv, int *dh, int days); /* mapper */
void spunit(struct strlist **SP, const struct faction *f,
const struct unit *u, int indent, int mode);
const struct unit *u, unsigned int indent, int mode);
int reports(void);
int write_reports(struct faction *f, time_t ltime);
@ -105,7 +105,7 @@ extern "C" {
void register_reporttype(const char *extension, report_fun write,
int flag);
int bufunit(const struct faction *f, const struct unit *u, int indent,
int bufunit(const struct faction *f, const struct unit *u, unsigned int indent,
int mode, char *buf, size_t size);
const char *trailinto(const struct region *r,

View File

@ -490,7 +490,7 @@ static const race *select_familiar(const race * magerace, magic_t magiegebiet)
unsigned int maxlen = listlen(familiarraces);
if (maxlen > 0) {
race_list *rclist = familiarraces;
int index = rng_int() % maxlen;
unsigned int index = rng_uint() % maxlen;
while (index-- > 0) {
rclist = rclist->next;
}
@ -536,7 +536,8 @@ static int sp_summon_familiar(castorder * co)
int cast_level = co->level;
const race *rc;
int sk;
int dh, dh1, bytes;
int dh, dh1;
size_t bytes;
message *msg;
char zText[2048], *bufp = zText;
size_t size = sizeof(zText) - 1;
@ -597,17 +598,17 @@ static int sp_summon_familiar(castorder * co)
else {
if (dh == 0) {
bytes =
(int)strlcpy(bufp, (const char *)LOC(mage->faction->locale,
strlcpy(bufp, (const char *)LOC(mage->faction->locale,
"list_and"), size);
}
else {
bytes = (int)strlcpy(bufp, (const char *)", ", size);
bytes = strlcpy(bufp, (const char *)", ", size);
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
bytes =
(int)strlcpy(bufp, (const char *)skillname((skill_t)sk, mage->faction->locale),
strlcpy(bufp, (const char *)skillname((skill_t)sk, mage->faction->locale),
size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
@ -908,7 +909,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);
@ -1299,16 +1300,17 @@ static int sp_rosthauch(castorder * co)
for (; iweapon != NULL; iweapon = iweapon->next) {
item **ip = i_find(&u->items, iweapon->type);
if (*ip) {
int i = _min((*ip)->number, force);
float chance = (float)_min((*ip)->number, force);
if (iweapon->chance < 1.0) {
i = (int)(i * iweapon->chance);
chance *= iweapon->chance;
}
if (i > 0) {
force -= i;
ironweapon += i;
i_change(ip, iweapon->type, -i);
if (chance > 0) {
int ichange = (int)chance;
force -= ichange;
ironweapon += ichange;
i_change(ip, iweapon->type, -ichange);
if (iweapon->rusty) {
i_change(&u->items, iweapon->rusty, i);
i_change(&u->items, iweapon->rusty, ichange);
}
}
}
@ -4004,7 +4006,7 @@ static int sp_recruit(castorder * co)
* Bauer, nur die Kosten steigen. */
n = (pow(force, 1.6) * 100) / f->race->recruitcost;
if (rc->recruit_multi != 0) {
double multp = maxp / rc->recruit_multi;
double multp = (double)maxp / rc->recruit_multi;
n = _min(multp, n);
n = _max(n, 1);
rsetpeasants(r, maxp - (int)(n * rc->recruit_multi));
@ -4054,7 +4056,7 @@ static int sp_bigrecruit(castorder * co)
/* Fuer vergleichbare Erfolge bei unterschiedlichen Rassen die
* Rekrutierungskosten mit einfliessen lassen. */
n = (int)force + lovar((force * force * 1000) / f->race->recruitcost);
n = (int)force + lovar((force * force * 1000) / (float)f->race->recruitcost);
if (f->race == get_race(RC_ORC)) {
n = _min(2 * maxp, n);
n = _max(n, 1);
@ -4197,7 +4199,7 @@ static int sp_seduce(castorder * co)
loot += rng_int() % 2;
}
if (loot > 0) {
loot = (int)_min(loot, force * 5);
loot = _min(loot, (int)(force * 5));
}
}
if (loot > 0) {
@ -4314,7 +4316,7 @@ static int sp_headache(castorder * co)
}
if (smax != NULL) {
/* wirkt auf maximal 10 Personen */
int change = _min(10, target->number) * (rng_int() % 2 + 1) / target->number;
unsigned int change = _min(10, target->number) * (rng_uint() % 2 + 1) / target->number;
reduce_skill(target, smax, change);
}
set_order(&target->thisorder, NULL);
@ -4358,7 +4360,7 @@ static int sp_raisepeasants(castorder * co)
"error_nopeasants", ""));
return 0;
}
bauern = (int)_min(rpeasants(r), power * 250);
bauern = _min(rpeasants(r), (int)(power * 250));
rsetpeasants(r, rpeasants(r) - bauern);
u2 =

View File

@ -7,7 +7,7 @@
#include "bsdstring.h"
int wrptr(char **ptr, size_t * size, int bytes)
int wrptr(char **ptr, size_t * size, size_t bytes)
{
if (bytes == 0) {
return 0;

View File

@ -2,7 +2,7 @@
#define UTIL_BSDSTRING_H
#include <stddef.h>
extern int wrptr(char **ptr, size_t * size, int bytes);
extern int wrptr(char **ptr, size_t * size, size_t bytes);
#ifndef HAVE_STRLCPY
extern size_t strlcpy(char *dst, const char *src, size_t siz);

View File

@ -29,7 +29,8 @@ extern "C" {
long genrand_int31(void);
# define rng_init(seed) init_genrand(seed)
# define rng_int genrand_int31
# define rng_int (int)genrand_int31
# define rng_uint (unsigned int)genrand_int32
# define rng_double genrand_real2
# define RNG_RAND_MAX 0x7fffffff
#else