]> granicus.if.org Git - nethack/commitdiff
Fix segfault when farlooking monster under generic object
authorPasi Kallinen <paxed@alt.org>
Sat, 4 Feb 2023 15:48:53 +0000 (17:48 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 4 Feb 2023 15:48:57 +0000 (17:48 +0200)
A detected cave spider was hiding under a generic spellbook object;
farlooking at it produced a segfault.  OBJ_NAME is null for the generic
objects, so don't try to strcmp it.

src/objnam.c

index 960247ac32f22313a750e89887f4b7057c757ec5..707d022f4533687b82ac36ed7fbe067360ed11a3 100644 (file)
@@ -2139,7 +2139,7 @@ ansimpleoname(struct obj* obj)
        any `known' and `dknown' checking necessary) */
     if (otyp == FAKE_AMULET_OF_YENDOR)
         otyp = AMULET_OF_YENDOR;
-    if (objects[otyp].oc_unique
+    if (objects[otyp].oc_unique && OBJ_NAME(objects[otyp])
         && !strcmp(simpleoname, OBJ_NAME(objects[otyp]))) {
         /* the() will allocate another obuf[]; we want to avoid using two */
         Strcpy(simpleoname, obufp = the(simpleoname));