From fe29e29c317a47958b0e4a4ec8e0820b1c2b48c2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 May 2015 06:43:47 +0200 Subject: [PATCH] fix -Wconversion for move.c --- src/move.c | 25 ++++++++++++++----------- src/move.h | 2 +- src/util/bsdstring.c | 2 +- src/util/bsdstring.h | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/move.c b/src/move.c index 54864b89e..0812ae794 100644 --- a/src/move.c +++ b/src/move.c @@ -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++; diff --git a/src/move.h b/src/move.h index 11e6b3954..f1c20d622 100644 --- a/src/move.h +++ b/src/move.h @@ -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); diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index f1694eed6..2cbf630d6 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -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; diff --git a/src/util/bsdstring.h b/src/util/bsdstring.h index 91b89465d..200ca30a6 100644 --- a/src/util/bsdstring.h +++ b/src/util/bsdstring.h @@ -2,7 +2,7 @@ #define UTIL_BSDSTRING_H #include -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);