]> granicus.if.org Git - nethack/commitdiff
Fix segfault when looking at detected monster hiding under unknown armor
authorPasi Kallinen <paxed@alt.org>
Fri, 2 Dec 2016 20:03:10 +0000 (22:03 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 2 Dec 2016 20:12:44 +0000 (22:12 +0200)
This segfault happened when a detected monster such as a garter snake was
hiding under an unknown/unseen armor of a type that has no description
field (eg. a leather armor), and you farlooked at the monster.

At the same time, simplifies the code a tiny bit.

src/objnam.c

index d395ea74751ef7e6a518412843f1362e45c69e3f..7a800d23a7599ea6eb7d1191c7889a127d9b5ffa 100644 (file)
@@ -268,7 +268,7 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */
     register struct objclass *ocl = &objects[typ];
     int nn = ocl->oc_name_known, omndx = obj->corpsenm;
     const char *actualn = OBJ_NAME(*ocl);
-    const char *dn = OBJ_DESCR(*ocl);
+    const char *dn = OBJ_DESCR(*ocl) ? OBJ_DESCR(*ocl) : actualn;
     const char *un = ocl->oc_uname;
     boolean pluralize = (obj->quan != 1L) && !(cxn_flags & CXN_SINGULAR);
     boolean known, dknown, bknown;
@@ -327,15 +327,15 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */
             Strcpy(buf, (obj->spe < 3) ? "moist " : "wet ");
 
         if (!dknown)
-            Strcat(buf, dn ? dn : actualn);
+            Strcat(buf, dn);
         else if (nn)
             Strcat(buf, actualn);
         else if (un) {
-            Strcat(buf, dn ? dn : actualn);
+            Strcat(buf, dn);
             Strcat(buf, " called ");
             Strcat(buf, un);
         } else
-            Strcat(buf, dn ? dn : actualn);
+            Strcat(buf, dn);
         /* If we use an() here we'd have to remember never to use */
         /* it whenever calling doname() or xname(). */
         if (typ == FIGURINE && omndx != NON_PM) {