From 407a2e0ea8d0ccf7f0d575d8567abeebf73e14cb Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 10 Aug 2025 12:45:29 -0700 Subject: [PATCH] fix issue #1436 - object_from_map() vs Hallu Issue reported by janne-hmp: examining an object on the map while halluicinating might operate on an object whose name is Null since the random object could be one that holds an extra description for item shuffling at game start. Attempting to format the object led to a crash. I wasn't able to reproduce the crash, possibly because MacOS produces the string "(null)" for sprintf("%s",NULL) instead of dereferencing the Null pointer. Perhaps random object selection for display should reject the extra description objects in some classes. This susbstitutes a different object if examining the map encounters one of those. Fixes #1436 --- doc/fixes3-7-0.txt | 3 +++ src/pager.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index d19a70a6e..fb87d1121 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1525,6 +1525,9 @@ a vampire lord could choose to take on wolf form while flying over water or lava, then revert to vampire lord form and teleport unnecessarily a gas spore that was killed when an engulfer swallowed it produced an explosion on the map rather than inside the engulfer +hallucination can display objects on the map that have a description (for + shuffling into play at game start) but no name; examining those might + trigger a crash Fixes to 3.7.0-x General Problems Exposed Via git Repository diff --git a/src/pager.c b/src/pager.c index e2e0c06a9..061937687 100644 --- a/src/pager.c +++ b/src/pager.c @@ -312,7 +312,20 @@ object_from_map( if (!otmp || otmp->otyp != glyphotyp) { /* this used to exclude STRANGE_OBJECT; now caller deals with it */ - otmp = mksobj(glyphotyp, FALSE, FALSE); + if (OBJ_NAME(objects[glyphotyp])) { + /* map shows a regular object, but one that's not actually here */ + otmp = mksobj(glyphotyp, FALSE, FALSE); + } else { + /* map shows a non-item that holds an extra object type (shown + on map due to hallucination) for a name which might have been + shuffled into play but wasn't (or was shuffled out of play); + pick another item that is a regular one in same object class */ + otmp = mkobj(objects[glyphotyp].oc_class, FALSE); + /* mkobj() doesn't provide any no-init option; however, there + aren't any extra tool items (or statues) so we won't get here + for tools and don't need to check for and delete container + contents or extinguish lights on the temporary object */ + } /* even though we pass False for mksobj()'s 'init' arg, corpse-rot, egg-hatch, and figurine-transform timers get initialized */ if (otmp->timed)