static analyzer bit for weapon.c
src/weapon.c(451): warning: Dereferencing NULL pointer 'uleft'. The analyzer couldn't tell that a STRANGE_OBJECT not being made of SILVER material, was sufficient to guard against dereference of NULL uleft or uright in the l_ag and r_ag assignments. Test and dereference each once to set indicator booleans, and use the booleans afterwards.
This commit is contained in:
@@ -438,8 +438,10 @@ silver_sears(struct monst *magr UNUSED, struct monst *mdef,
|
|||||||
rtyp = ((uright && (silverhit & W_RINGR) != 0L)
|
rtyp = ((uright && (silverhit & W_RINGR) != 0L)
|
||||||
? uright->otyp : STRANGE_OBJECT);
|
? uright->otyp : STRANGE_OBJECT);
|
||||||
boolean both,
|
boolean both,
|
||||||
l_ag = (objects[ltyp].oc_material == SILVER && uleft->dknown),
|
l_dknown = (uleft && uleft->dknown),
|
||||||
r_ag = (objects[rtyp].oc_material == SILVER && uright->dknown);
|
r_dknown = (uright && uright->dknown),
|
||||||
|
l_ag = (objects[ltyp].oc_material == SILVER && l_dknown),
|
||||||
|
r_ag = (objects[rtyp].oc_material == SILVER && r_dknown);
|
||||||
|
|
||||||
if ((silverhit & (W_RINGL | W_RINGR)) != 0L) {
|
if ((silverhit & (W_RINGL | W_RINGR)) != 0L) {
|
||||||
/* plural if both the same type (so not multi_claw and both rings
|
/* plural if both the same type (so not multi_claw and both rings
|
||||||
@@ -448,8 +450,7 @@ silver_sears(struct monst *magr UNUSED, struct monst *mdef,
|
|||||||
and both known; singular if multi_claw (where one of ltyp or
|
and both known; singular if multi_claw (where one of ltyp or
|
||||||
rtyp will always be STRANGE_OBJECT) even if both rings are known
|
rtyp will always be STRANGE_OBJECT) even if both rings are known
|
||||||
silver [see hmonas(uhitm.c) for explanation of 'multi_claw'] */
|
silver [see hmonas(uhitm.c) for explanation of 'multi_claw'] */
|
||||||
both = ((ltyp == rtyp && uleft->dknown == uright->dknown)
|
both = ((ltyp == rtyp && l_dknown == r_dknown) || (l_ag && r_ag));
|
||||||
|| (l_ag && r_ag));
|
|
||||||
Sprintf(rings, "ring%s", both ? "s" : "");
|
Sprintf(rings, "ring%s", both ? "s" : "");
|
||||||
Your("%s%s %s %s!",
|
Your("%s%s %s %s!",
|
||||||
(l_ag || r_ag) ? "silver "
|
(l_ag || r_ag) ? "silver "
|
||||||
|
|||||||
Reference in New Issue
Block a user