]> granicus.if.org Git - nethack/commitdiff
LIMIT_TO_RANGE_INT macro and various casts.
authornhkeni <keni@his.com>
Wed, 16 Mar 2022 21:59:23 +0000 (17:59 -0400)
committernhkeni <keni@his.com>
Wed, 16 Mar 2022 21:59:23 +0000 (17:59 -0400)
include/hack.h
src/do_wear.c
src/dothrow.c
src/hack.c
src/read.c

index f30e7394d619cfd4f61f6642b8fcc3b2f6b07f83..7be2672a2c564acebb58719eb0a4d2d2623a1a17 100644 (file)
@@ -642,6 +642,15 @@ enum optset_restrictions {
 #endif
 #define plur(x) (((x) == 1) ? "" : "s")
 
+/* Cast to int, but limit value to range. */
+#define LIMIT_TO_RANGE_INT(lo, hi, var) \
+    (int) (                             \
+       (var) < (lo) ? (lo) : (         \
+           (var) > (hi) ? (hi) :       \
+           (var)                       \
+       )                               \
+    )
+
 #define ARM_BONUS(obj)                      \
     (objects[(obj)->otyp].a_ac + (obj)->spe \
      - min((int) greatest_erosion(obj), objects[(obj)->otyp].a_ac))
index 9255124480ae2c36bcf0d93810db4a331334eb33..7f01697c7e48bbbdb02ff83b6f206f3059b65779 100644 (file)
@@ -1533,7 +1533,7 @@ stop_donning(struct obj *stolenobj) /* no message if stolenobj is already
                 thesimpleoname(otmp));
     } else {
         buf[0] = '\0';   /* silently stop doffing stolenobj */
-        result = -g.multi; /* remember this before calling unmul() */
+        result = (int) -g.multi; /* remember this before calling unmul() */
     }
     unmul(buf);
     /* while putting on, item becomes worn immediately but side-effects are
index bdd35db79037678306004ec38e214425d90db678..f171b29890b524673e22be49c412c4f10784f610 100644 (file)
@@ -257,7 +257,7 @@ throw_obj(struct obj *obj, int shotlimit)
 static boolean
 ok_to_throw(int *shotlimit_p) /* (see dothrow()) */
 {
-    *shotlimit_p = g.command_count;
+    *shotlimit_p = LIMIT_TO_RANGE_INT(0, LARGEST_INT, g.command_count);
     g.multi = 0; /* reset; it's been used up */
 
     if (notake(g.youmonst.data)) {
index 603f0a05fde18d1959598da416c22dce38584d55..68650075e1853b1927ce213047a4aab4948fbc4f 100644 (file)
@@ -3176,7 +3176,7 @@ dopickup(void)
 {
     int count, tmpcount, ret;
 
-    count = g.command_count;
+    count = (int) g.command_count;
     g.multi = 0; /* always reset */
 
     if ((ret = pickup_checks()) >= 0) {
index db8800b86bb181775cfe67dda6ee027e8eca1035..f19252181f8374b00fe257f4227da77c67513b16 100644 (file)
@@ -2894,7 +2894,7 @@ create_particular_parse(char* str, struct _create_particular_data* d)
     char *bufp = str;
     char *tmpp;
 
-    d->quan = 1 + ((g.multi > 0) ? g.multi : 0);
+    d->quan = 1 + ((g.multi > 0) ? (int) g.multi : 0);
     d->monclass = MAXMCLASSES;
     d->which = g.urole.mnum; /* an arbitrary index into mons[] */
     d->fem = -1;     /* gender not specified */