]> granicus.if.org Git - nethack/commitdiff
glob pricing
authorPatR <rankin@nethack.org>
Sat, 5 Oct 2019 00:53:01 +0000 (17:53 -0700)
committerPatR <rankin@nethack.org>
Sat, 5 Oct 2019 00:53:01 +0000 (17:53 -0700)
get_pricing_units() returns a long, so use long for intermediate steps
of the calculation.  Part of github issue 229, about mixing signed and
unsigned.

src/shk.c

index f5c42bacd6a80422c9200cb1776a51e14bfe1ccb..5fcc70c99652f1dc0b732553fe34d90688033030 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 shk.c   $NHDT-Date: 1558124088 2019/05/17 20:14:48 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.163 $ */
+/* NetHack 3.6 shk.c   $NHDT-Date: 1570236762 2019/10/05 00:52:42 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.168 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -2035,11 +2035,11 @@ struct obj *obj;
 
     if (obj->globby) {
         /* globs must be sold by weight not by volume */
-        int unit_weight = (int) objects[obj->otyp].oc_weight,
-            wt = (obj->owt > 0) ? obj->owt : weight(obj);
+        long unit_weight = (long) objects[obj->otyp].oc_weight,
+             wt = (obj->owt > 0) ? (long) obj->owt : (long) weight(obj);
 
         if (unit_weight)
-            units = wt / unit_weight;
+            units = (wt + unit_weight - 1L) / unit_weight;
     }
     return units;
 }