From eac4ef7ddcd3609d168b1f2cc1421f81a37dfc8e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 May 2015 13:32:22 +0200 Subject: [PATCH] reduce conversion warning to float only --- src/CMakeLists.txt | 2 +- src/economy.c | 40 +++++++++++++++++++++++----------------- src/kernel/messages.c | 8 ++++++++ src/kernel/messages.h | 1 + src/kernel/race.h | 6 +++--- src/report.c | 2 +- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea2c8d0e7..5c856bc17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ include_directories (${BSON_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR}) IF(CMAKE_COMPILER_IS_GNUCC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wconversion -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wfloat-conversion -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} /Wall /WX /MP") diff --git a/src/economy.c b/src/economy.c index fd548b1ae..643ff1f0e 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; - 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); } diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 9291592b1..49542ce4a 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -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) diff --git a/src/kernel/messages.h b/src/kernel/messages.h index c03dca1b7..4ce412bcd 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -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 diff --git a/src/kernel/race.h b/src/kernel/race.h index a81853915..47fe149e5 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -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; diff --git a/src/report.c b/src/report.c index 649eae934..a644e216f 100644 --- a/src/report.c +++ b/src/report.c @@ -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