From: cohrs Date: Sun, 20 Jan 2002 22:25:16 +0000 (+0000) Subject: xprname fix X-Git-Tag: MOVE2GIT~3412 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=202a38344479f3d16d8a9be13462a58b3cd6d08d;p=nethack xprname fix The GOLDOBJ fix I posted back on 1/3 caused "Ix" to access a null pointer (obj) while generating the total line. This patch fixes the bug I added to xprname. --- diff --git a/src/invent.c b/src/invent.c index 816b87705..2d15caee1 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1428,9 +1428,13 @@ long quan; /* if non-0, print this quantity, not obj->quan */ static char li[BUFSZ]; #endif boolean use_invlet = flags.invlet_constant && let != CONTAINED_SYM; - long savequan = obj->quan; + long savequan = 0; + + if (quan && obj) { + savequan = obj->quan; + obj->quan = quan; + } - if (quan) obj->quan = quan; /* * If let is: * * Then obj == null and we are printing a total amount. @@ -1442,7 +1446,7 @@ long quan; /* if non-0, print this quantity, not obj->quan */ (dot && use_invlet ? obj->invlet : let), (txt ? txt : doname(obj)), cost, plur(cost)); #ifndef GOLDOBJ - } else if (obj->oclass == GOLD_CLASS) { + } else if (obj && obj->oclass == GOLD_CLASS) { Sprintf(li, "%ld gold piece%s%s", obj->quan, plur(obj->quan), (dot ? "." : "")); #endif @@ -1452,7 +1456,7 @@ long quan; /* if non-0, print this quantity, not obj->quan */ (use_invlet ? obj->invlet : let), (txt ? txt : doname(obj)), (dot ? "." : "")); } - if (quan) obj->quan = savequan; + if (savequan) obj->quan = savequan; return li; }