U313 - crash applying figurine, cursed bell or candles

Reported for applying a figurine that was used up, but I found the same
problem could affect cursed bells and candles.  Modified all three helper
functions to indicate when the object is gone, and modified doapply to
deal with this before doing the artifact check.
This commit is contained in:
cohrs
2003-03-04 06:53:25 +00:00
parent 27977b7c15
commit 4d6cfb01a7
2 changed files with 21 additions and 14 deletions
+1
View File
@@ -3,6 +3,7 @@ $RCSfile$ $Revision$ $Date$
General Fixes and Modified Features General Fixes and Modified Features
----------------------------------- -----------------------------------
avoid panic when secondary weapon is cursed while generating bones level avoid panic when secondary weapon is cursed while generating bones level
don't crash when applying a figurine, candle, or bell that gets used up
Platform- and/or Interface-Specific Fixes Platform- and/or Interface-Specific Fixes
+20 -14
View File
@@ -21,13 +21,13 @@ STATIC_DCL void FDECL(use_whistle, (struct obj *));
STATIC_DCL void FDECL(use_magic_whistle, (struct obj *)); STATIC_DCL void FDECL(use_magic_whistle, (struct obj *));
STATIC_DCL void FDECL(use_leash, (struct obj *)); STATIC_DCL void FDECL(use_leash, (struct obj *));
STATIC_DCL int FDECL(use_mirror, (struct obj *)); STATIC_DCL int FDECL(use_mirror, (struct obj *));
STATIC_DCL void FDECL(use_bell, (struct obj *)); STATIC_DCL void FDECL(use_bell, (struct obj **));
STATIC_DCL void FDECL(use_candelabrum, (struct obj *)); STATIC_DCL void FDECL(use_candelabrum, (struct obj *));
STATIC_DCL void FDECL(use_candle, (struct obj *)); STATIC_DCL void FDECL(use_candle, (struct obj **));
STATIC_DCL void FDECL(use_lamp, (struct obj *)); STATIC_DCL void FDECL(use_lamp, (struct obj *));
STATIC_DCL void FDECL(light_cocktail, (struct obj *)); STATIC_DCL void FDECL(light_cocktail, (struct obj *));
STATIC_DCL void FDECL(use_tinning_kit, (struct obj *)); STATIC_DCL void FDECL(use_tinning_kit, (struct obj *));
STATIC_DCL void FDECL(use_figurine, (struct obj *)); STATIC_DCL void FDECL(use_figurine, (struct obj **));
STATIC_DCL void FDECL(use_grease, (struct obj *)); STATIC_DCL void FDECL(use_grease, (struct obj *));
STATIC_DCL void FDECL(use_trap, (struct obj *)); STATIC_DCL void FDECL(use_trap, (struct obj *));
STATIC_DCL void FDECL(use_stone, (struct obj *)); STATIC_DCL void FDECL(use_stone, (struct obj *));
@@ -725,9 +725,10 @@ struct obj *obj;
} }
STATIC_OVL void STATIC_OVL void
use_bell(obj) use_bell(optr)
register struct obj *obj; struct obj **optr;
{ {
register struct obj *obj = *optr;
struct monst *mtmp; struct monst *mtmp;
boolean wakem = FALSE, learno = FALSE, boolean wakem = FALSE, learno = FALSE,
ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe), ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe),
@@ -762,6 +763,7 @@ register struct obj *obj;
if (!obj_resists(obj, 93, 100)) { if (!obj_resists(obj, 93, 100)) {
pline("%s shattered!", Tobjnam(obj, "have")); pline("%s shattered!", Tobjnam(obj, "have"));
useup(obj); useup(obj);
*optr = 0;
} else switch (rn2(3)) { } else switch (rn2(3)) {
default: default:
break; break;
@@ -893,9 +895,10 @@ register struct obj *obj;
} }
STATIC_OVL void STATIC_OVL void
use_candle(obj) use_candle(optr)
register struct obj *obj; struct obj **optr;
{ {
register struct obj *obj = *optr;
register struct obj *otmp; register struct obj *otmp;
const char *s = (obj->quan != 1) ? "candles" : "candle"; const char *s = (obj->quan != 1) ? "candles" : "candle";
char qbuf[QBUFSZ]; char qbuf[QBUFSZ];
@@ -925,6 +928,7 @@ register struct obj *obj;
} else { } else {
if ((long)otmp->spe + obj->quan > 7L) if ((long)otmp->spe + obj->quan > 7L)
obj = splitobj(obj, 7L - (long)otmp->spe); obj = splitobj(obj, 7L - (long)otmp->spe);
else *optr = 0;
You("attach %ld%s %s to %s.", You("attach %ld%s %s to %s.",
obj->quan, !otmp->spe ? "" : " more", obj->quan, !otmp->spe ? "" : " more",
s, the(xname(otmp))); s, the(xname(otmp)));
@@ -1696,9 +1700,10 @@ boolean quietly;
} }
STATIC_OVL void STATIC_OVL void
use_figurine(obj) use_figurine(optr)
register struct obj *obj; struct obj **optr;
{ {
register struct obj *obj = *optr;
xchar x, y; xchar x, y;
coord cc; coord cc;
@@ -1726,6 +1731,7 @@ register struct obj *obj;
(void) make_familiar(obj, cc.x, cc.y, FALSE); (void) make_familiar(obj, cc.x, cc.y, FALSE);
(void) stop_timer(FIG_TRANSFORM, (genericptr_t)obj); (void) stop_timer(FIG_TRANSFORM, (genericptr_t)obj);
useup(obj); useup(obj);
*optr = 0;
} }
static NEARDATA const char lubricables[] = { ALL_CLASSES, ALLOW_NONE, 0 }; static NEARDATA const char lubricables[] = { ALL_CLASSES, ALLOW_NONE, 0 };
@@ -2712,7 +2718,7 @@ char class;
int int
doapply() doapply()
{ {
register struct obj *obj; struct obj *obj;
register int res = 1; register int res = 1;
char class_list[MAXOCLASSES+2]; char class_list[MAXOCLASSES+2];
@@ -2838,14 +2844,14 @@ doapply()
break; break;
case BELL: case BELL:
case BELL_OF_OPENING: case BELL_OF_OPENING:
use_bell(obj); use_bell(&obj);
break; break;
case CANDELABRUM_OF_INVOCATION: case CANDELABRUM_OF_INVOCATION:
use_candelabrum(obj); use_candelabrum(obj);
break; break;
case WAX_CANDLE: case WAX_CANDLE:
case TALLOW_CANDLE: case TALLOW_CANDLE:
use_candle(obj); use_candle(&obj);
break; break;
case OIL_LAMP: case OIL_LAMP:
case MAGIC_LAMP: case MAGIC_LAMP:
@@ -2882,7 +2888,7 @@ doapply()
goto xit; goto xit;
case FIGURINE: case FIGURINE:
use_figurine(obj); use_figurine(&obj);
break; break;
case UNICORN_HORN: case UNICORN_HORN:
use_unicorn_horn(obj); use_unicorn_horn(obj);
@@ -2960,7 +2966,7 @@ doapply()
nomul(0); nomul(0);
return 0; return 0;
} }
if (res && obj->oartifact) arti_speak(obj); if (res && obj && obj->oartifact) arti_speak(obj);
nomul(0); nomul(0);
return res; return res;
} }