From: Pasi Kallinen Date: Fri, 2 Dec 2016 20:03:10 +0000 (+0200) Subject: Fix segfault when looking at detected monster hiding under unknown armor X-Git-Tag: NetHack-3.6.1_RC01~551 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5da34b7db667d5de74e9f2881a7213584654593b;p=nethack Fix segfault when looking at detected monster hiding under unknown armor 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. --- diff --git a/src/objnam.c b/src/objnam.c index d395ea747..7a800d23a 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -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) {