From: nhkeni Date: Wed, 16 Mar 2022 22:18:52 +0000 (-0400) Subject: Various type and cast bits. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a64a666f7807d0f36b442be1ab6e1ffd8abd1f2d;p=nethack Various type and cast bits. --- diff --git a/include/global.h b/include/global.h index 1d5d7b26f..4ec90f84b 100644 --- a/include/global.h +++ b/include/global.h @@ -279,6 +279,8 @@ typedef uchar nhsym; declaration has been moved out of the '#else' below to avoid getting a complaint from -Wmissing-prototypes when building with MONITOR_HEAP */ extern char *dupstr(const char *); +/* same, but return strlen(string) */ +extern char *dupstr_n(const char *string, unsigned int *lenout); /* * MONITOR_HEAP is conditionally used for primitive memory leak debugging. diff --git a/src/alloc.c b/src/alloc.c index 872188cdf..df2c07b63 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -150,4 +150,15 @@ dupstr(const char *string) return strcpy((char *) alloc(strlen(string) + 1), string); } +/* similar for reasonable size strings, but return the length of the input as well */ +char * +dupstr_n(const char *string, unsigned int *lenout) +{ + size_t len = strlen(string); + if(len >= LARGEST_INT) + panic("string too long"); + *lenout = (unsigned int) len; + return strcpy((char *) alloc((unsigned)len + 1), string); +} + /*alloc.c*/ diff --git a/src/attrib.c b/src/attrib.c index f6c30e42a..b71ba46e0 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -1132,7 +1132,7 @@ adjalign(int n) } else if (newalign > u.ualign.record) { u.ualign.record = newalign; if (u.ualign.record > ALIGNLIM) - u.ualign.record = ALIGNLIM; + u.ualign.record = (int)ALIGNLIM; } } diff --git a/src/botl.c b/src/botl.c index 6d1b1d18d..45b5c77ea 100644 --- a/src/botl.c +++ b/src/botl.c @@ -3045,7 +3045,7 @@ status_hilite_linestr_gather_conditions(void) int i; struct _cond_map { unsigned long bm; - unsigned long clratr; + unsigned int clratr; } cond_maps[SIZE(conditions)]; (void) memset(cond_maps, 0, @@ -3075,7 +3075,7 @@ status_hilite_linestr_gather_conditions(void) atr &= ~HL_NONE; if (clr != NO_COLOR || atr != HL_NONE) { - unsigned long ca = clr | (atr << 8); + unsigned int ca = clr | (atr << 8); boolean added_condmap = FALSE; for (j = 0; j < SIZE(conditions); j++) diff --git a/src/dlb.c b/src/dlb.c index 6b631796a..642951fc5 100644 --- a/src/dlb.c +++ b/src/dlb.c @@ -298,7 +298,7 @@ lib_dlb_fread(char *buf, int size, int quan, dlb *dp) /* make sure we don't read into the next file */ if ((dp->size - dp->mark) < (size * quan)) - quan = (dp->size - dp->mark) / size; + quan = (int)((dp->size - dp->mark) / size); if (quan == 0) return 0; @@ -313,7 +313,7 @@ lib_dlb_fread(char *buf, int size, int quan, dlb *dp) dp->mark += nbytes; dp->lib->fmark += nbytes; - return nread; + return (int)nread; } static int diff --git a/src/do.c b/src/do.c index c74d2033d..58ce0286b 100644 --- a/src/do.c +++ b/src/do.c @@ -11,7 +11,7 @@ static void polymorph_sink(void); static boolean teleport_sink(void); static void dosinkring(struct obj *); static int drop(struct obj *); -static int menudrop_split(struct obj *, int); +static int menudrop_split(struct obj *, long); static boolean engulfer_digests_food(struct obj *); static int wipeoff(void); static int menu_drop(int); @@ -838,7 +838,7 @@ doddrop(void) } static int /* check callers */ -menudrop_split(struct obj *otmp, int cnt) +menudrop_split(struct obj *otmp, long cnt) { if (cnt && cnt < otmp->quan) { if (welded(otmp)) { diff --git a/src/eat.c b/src/eat.c index 183c5c19d..2b464802d 100644 --- a/src/eat.c +++ b/src/eat.c @@ -1762,7 +1762,7 @@ eatcorpse(struct obj *otmp) ? herbivorous(g.youmonst.data) : carnivorous(g.youmonst.data)) && rn2(10) - && ((rotted < 1) ? TRUE : !rn2(rotted+1))); + && ((rotted < 1) ? TRUE : !rn2((int)rotted+1))); const char *pmxnam = food_xname(otmp, FALSE); if (!strncmpi(pmxnam, "the ", 4)) diff --git a/src/files.c b/src/files.c index 715d7fa40..27388d31b 100644 --- a/src/files.c +++ b/src/files.c @@ -3034,7 +3034,7 @@ read_config_file(const char *filename, int src) struct _cnf_parser_state { char *inbuf; - size_t inbufsz; + unsigned inbufsz; int rv; char *ep; char *buf; diff --git a/src/mkroom.c b/src/mkroom.c index c1fc92a92..ed6d7b03a 100644 --- a/src/mkroom.c +++ b/src/mkroom.c @@ -520,7 +520,7 @@ mkswamp(void) /* Michiel Huisjes & Fred de Wilde */ || has_dnstairs(sroom)) continue; - rmno = (sroom - g.rooms) + ROOMOFFSET; + rmno = (int)(sroom - g.rooms) + ROOMOFFSET; /* satisfied; make a swamp */ sroom->rtype = SWAMP; diff --git a/src/mthrowu.c b/src/mthrowu.c index 2fca18fb6..a9ae4053d 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -235,7 +235,7 @@ monmulti(struct monst* mtmp, struct obj* otmp, struct obj* mwep) if (ammo_and_launcher(otmp, mwep) && mwep->spe > 1) multishot += (long) rounddiv(mwep->spe, 3); /* Some randomness */ - multishot = (long) rnd((int) multishot); + multishot = rnd((int) multishot); /* class bonus */ multishot += multishot_class_bonus(monsndx(mtmp->data), otmp, mwep); diff --git a/src/read.c b/src/read.c index f19252181..003fe15bc 100644 --- a/src/read.c +++ b/src/read.c @@ -2142,7 +2142,7 @@ drop_boulder_on_player(boolean confused, boolean helmet_protects, boolean byu, b if (!amorphous(g.youmonst.data) && !Passes_walls && !noncorporeal(g.youmonst.data) && !unsolid(g.youmonst.data)) { You("are hit by %s!", doname(otmp2)); - dmg = dmgval(otmp2, &g.youmonst) * otmp2->quan; + dmg = (int) (dmgval(otmp2, &g.youmonst) * otmp2->quan); if (uarmh && helmet_protects) { if (is_metallic(uarmh)) { pline("Fortunately, you are wearing a hard helmet."); @@ -2183,7 +2183,7 @@ drop_boulder_on_monster(int x, int y, boolean confused, boolean byu) if (mtmp && !amorphous(mtmp->data) && !passes_walls(mtmp->data) && !noncorporeal(mtmp->data) && !unsolid(mtmp->data)) { struct obj *helmet = which_armor(mtmp, W_ARMH); - int mdmg; + long mdmg; if (cansee(mtmp->mx, mtmp->my)) { pline("%s is hit by %s!", Monnam(mtmp), doname(otmp2)); diff --git a/src/version.c b/src/version.c index f33bfb42b..5edf0e376 100644 --- a/src/version.c +++ b/src/version.c @@ -327,7 +327,8 @@ check_version(struct version_info *version_data, const char *filename, boolean uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags) { - int rlen = 0, cmc = 0, filecmc = 0; + ssize_t rlen = 0; + int cmc = 0, filecmc = 0; struct version_info vers_info; boolean verbose = name ? TRUE : FALSE; char indicator;