]> granicus.if.org Git - nethack/commitdiff
generic object fix
authorPatR <rankin@nethack.org>
Sun, 15 Jan 2023 19:04:35 +0000 (11:04 -0800)
committerPatR <rankin@nethack.org>
Sun, 15 Jan 2023 19:04:35 +0000 (11:04 -0800)
When hallucinating, random object selection for objects was including
the new generic objects.  It was already excluding 'strange object'
by using 'rn2(NUM_OBJECTS - 1) + 1' to skip objects[0]; changing that
to be 'rn2(NUM_OBJECTS - MAXOCLASSES) + MAXOCLASSES' will skip the
first 18 objects, 'strange object' plus the 17 generic objects.

(I'm trying to convince myself that there's no off-by-1 or off-by-N
error and think I've succeeded.)

doc/fixes3-7-0.txt
include/display.h
src/pager.c

index 574b9da4565476c3746ab2765ab7035bf6c44cd9..0e370f9321eeb04a374c509c5cbf6df87c446dc7 100644 (file)
@@ -1457,6 +1457,10 @@ adding command line 'nethack --usage' broke 'nethack -u name' (however,
 being hit by a big monster and getting knockback effect could send hero out
        of a shop (or into its "free spot") while carrying unpaid goods;
        robbery wasn't noticed until hero eventually moved to a different spot
+hallucination of objects incorrectly included generic objects as candidates
+       for what objects looked like; if an object had its dknown flag set,
+       formatting a generic object in its place was unreliable (Null pointer
+       deference prior to static analyzer fix, odd fake name "generic" after)
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index a09ddf027a238fbac70cad03e5960e15b47fb0bd..ece52cd135d487122a6a5d9b13807656fbbe9078 100644 (file)
  * random_object()
  *
  * Respectively return a random monster or object.
+ * random_object() won't return STRANGE_OBJECT or the generic objects.
+ * -/+ MAXOCLASSES is used to skip it and them.
  */
-#define random_monster(rng) rng(NUMMONS)
-#define random_object(rng) (rng(NUM_OBJECTS - 1) + 1)
+#define random_monster(rng) ((*rng)(NUMMONS))
+#define random_object(rng) ((*rng)(NUM_OBJECTS - MAXOCLASSES) + MAXOCLASSES)
 
 /*
  * what_obj()
index adb6d93ca736420d194ac4245376eaaf2f8e0b7d..3da66038e688287df355e4d6b995a324de6b98ef 100644 (file)
@@ -332,10 +332,11 @@ look_at_object(
 }
 
 static void
-look_at_monster(char *buf,
-                char *monbuf, /* buf: output, monbuf: optional output */
-                struct monst *mtmp,
-                coordxy x, coordxy y)
+look_at_monster(
+    char *buf,
+    char *monbuf, /* buf: output, monbuf: optional output */
+    struct monst *mtmp,
+    coordxy x, coordxy y)
 {
     char *name, monnambuf[BUFSZ], healthbuf[BUFSZ];
     boolean accurate = !Hallucination;