]> granicus.if.org Git - nethack/commitdiff
Various type and cast bits.
authornhkeni <keni@his.com>
Wed, 16 Mar 2022 22:18:52 +0000 (18:18 -0400)
committernhkeni <keni@his.com>
Wed, 16 Mar 2022 22:18:52 +0000 (18:18 -0400)
12 files changed:
include/global.h
src/alloc.c
src/attrib.c
src/botl.c
src/dlb.c
src/do.c
src/eat.c
src/files.c
src/mkroom.c
src/mthrowu.c
src/read.c
src/version.c

index 1d5d7b26fc19f40d2d9fe90e3dbf21ad6e8e6dc5..4ec90f84baa00b653e81b15b1ba2eb35497bb96a 100644 (file)
@@ -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.
index 872188cdf516856c3b6b40501bb759952047cb97..df2c07b632ce51ca4cc3deff9e4bff27ed6be9aa 100644 (file)
@@ -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*/
index f6c30e42aba5df80b819483e9981142f3ae07977..b71ba46e0502f0ce5f5e5baedc25f6d13af41183 100644 (file)
@@ -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;
     }
 }
 
index 6d1b1d18dec16a188dbe55245b58ffc58014f234..45b5c77eaa60af377616906aa1fcaa923717969f 100644 (file)
@@ -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++)
index 6b631796a43c6eadc113e239d2a46eaa9e3a21c9..642951fc55dc57f55a89274f1aedb9794bf2d07f 100644 (file)
--- 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
index c74d2033d0306e240cd50d7b10c66d7e6fbb56dd..58ce0286bfa3dd4b1a709935dfcccbacef606e47 100644 (file)
--- 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)) {
index 183c5c19d08f7a5667fc24fcdd527f9a3df200bc..2b464802da49f94613fe1a41a3c15d38b29760e4 100644 (file)
--- 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))
index 715d7fa40ee648f4794642f296b0f022c8ae9c33..27388d31b37eddfcca84b75daa99ad1eb7606f28 100644 (file)
@@ -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;
index c1fc92a921fe1b70cd7d1b2522dfd54c100b7178..ed6d7b03a5cbf2ced842305e91dbe732f8ce802a 100644 (file)
@@ -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;
index 2fca18fb62bf76e436d079a5c88b9e924fa8f714..a9ae4053ddc307e5135279d28950ca7fd557e22a 100644 (file)
@@ -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);
index f19252181f8374b00fe257f4227da77c67513b16..003fe15bc1e030d13171dbdbeb3bc1e9f33693bc 100644 (file)
@@ -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));
index f33bfb42bfc029ea558e102d2d6e3d1982eee71c..5edf0e376855bce2bb62dbc6eed5fa24e4416823 100644 (file)
@@ -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;