fix #H9266 - redundant obj init
Sword given to angels used obj->spe = max(obj->spe, rn2(4)) [except using a temporary to sanely work with max() macro]. But the obj was explicitly created as no-init, so obj->spe was always 0 and the max() was pointless. Shield given to angels was manipulating bless/curse state directly instead of using the functions intended for that, a no-no and also pointless to be clearing 'cursed' for a no-init item. Mace for priests had useless handling for object creation failure. Object creation failure could only happen if the mksobj() call had a valid entry in objects[] (or out of bounds access that didn't crash) for an object class that it doesn't know how to handle. That can't happen unless somebody screws up big time. If it ever did happen, it would have produced a memory leak.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 makemon.c $NHDT-Date: 1561236435 2019/06/22 20:47:15 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.138 $ */
|
||||
/* NetHack 3.6 makemon.c $NHDT-Date: 1570569787 2019/10/08 21:23:07 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.140 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Robert Patrick Rankin, 2012. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -166,7 +166,7 @@ register struct monst *mtmp;
|
||||
register struct permonst *ptr = mtmp->data;
|
||||
register int mm = monsndx(ptr);
|
||||
struct obj *otmp;
|
||||
int bias, spe2, w1, w2;
|
||||
int bias, w1, w2;
|
||||
|
||||
if (Is_rogue_level(&u.uz))
|
||||
return;
|
||||
@@ -259,12 +259,10 @@ register struct monst *mtmp;
|
||||
} else if (ptr->msound == MS_PRIEST
|
||||
|| quest_mon_represents_role(ptr, PM_PRIEST)) {
|
||||
otmp = mksobj(MACE, FALSE, FALSE);
|
||||
if (otmp) {
|
||||
otmp->spe = rnd(3);
|
||||
if (!rn2(2))
|
||||
curse(otmp);
|
||||
(void) mpickobj(mtmp, otmp);
|
||||
}
|
||||
otmp->spe = rnd(3);
|
||||
if (!rn2(2))
|
||||
curse(otmp);
|
||||
(void) mpickobj(mtmp, otmp);
|
||||
} else if (mm == PM_NINJA) { /* extra quest villains */
|
||||
(void) mongets(mtmp, rn2(4) ? SHURIKEN : DART);
|
||||
(void) mongets(mtmp, rn2(4) ? SHORT_SWORD : AXE);
|
||||
@@ -336,14 +334,13 @@ register struct monst *mtmp;
|
||||
artiname(rn2(2) ? ART_DEMONBANE : ART_SUNSWORD));
|
||||
bless(otmp);
|
||||
otmp->oerodeproof = TRUE;
|
||||
spe2 = rn2(4);
|
||||
otmp->spe = max(otmp->spe, spe2);
|
||||
otmp->spe = rn2(4);
|
||||
(void) mpickobj(mtmp, otmp);
|
||||
|
||||
otmp = mksobj(!rn2(4) || is_lord(ptr) ? SHIELD_OF_REFLECTION
|
||||
: LARGE_SHIELD,
|
||||
FALSE, FALSE);
|
||||
otmp->cursed = FALSE;
|
||||
/* uncurse(otmp); -- mksobj(,FALSE,) item is always uncursed */
|
||||
otmp->oerodeproof = TRUE;
|
||||
otmp->spe = 0;
|
||||
(void) mpickobj(mtmp, otmp);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 mkobj.c $NHDT-Date: 1570566379 2019/10/08 20:26:19 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.152 $ */
|
||||
/* NetHack 3.6 mkobj.c $NHDT-Date: 1570569798 2019/10/08 21:23:18 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.153 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Derek S. Ray, 2015. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -1064,6 +1064,7 @@ boolean artif;
|
||||
default:
|
||||
impossible("impossible mkobj %d, sym '%c'.", otmp->otyp,
|
||||
objects[otmp->otyp].oc_class);
|
||||
dealloc_obj(otmp); /* free() would suffice here */
|
||||
return (struct obj *) 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user