avoid drinksink() complaint from gcc13.1 -fanalyze
'Fix' fountain.c:598:18: warning: check of 'otmp' for NULL after already dereferencing it [-Wanalyzer-deref-before-check] The original code was ok. Either the analyzer has a bug or NONNULL in extern.h's 'extern struct obj *mkobj(int, boolean) NONNULL;' is not expanding to the expected value. This replacement code should be easier to comprehend and with any luck be simpler to analyze.
This commit is contained in:
+7
-7
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.7 fountain.c $NHDT-Date: 1646870844 2022/03/10 00:07:24 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.78 $ */
|
/* NetHack 3.7 fountain.c $NHDT-Date: 1687058871 2023/06/18 03:27:51 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.95 $ */
|
||||||
/* Copyright Scott R. Turner, srt@ucla, 10/27/86 */
|
/* Copyright Scott R. Turner, srt@ucla, 10/27/86 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -590,13 +590,13 @@ drinksink(void)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
do {
|
for (;;) {
|
||||||
otmp = mkobj(POTION_CLASS, FALSE);
|
otmp = mkobj(POTION_CLASS, FALSE);
|
||||||
if (otmp->otyp == POT_WATER) {
|
if (otmp->otyp != POT_WATER)
|
||||||
obfree(otmp, (struct obj *) 0);
|
break;
|
||||||
otmp = (struct obj *) 0;
|
/* reject water and try again */
|
||||||
}
|
obfree(otmp, (struct obj *) 0);
|
||||||
} while (!otmp);
|
}
|
||||||
otmp->cursed = otmp->blessed = 0;
|
otmp->cursed = otmp->blessed = 0;
|
||||||
pline("Some %s liquid flows from the faucet.",
|
pline("Some %s liquid flows from the faucet.",
|
||||||
Blind ? "odd" : hcolor(OBJ_DESCR(objects[otmp->otyp])));
|
Blind ? "odd" : hcolor(OBJ_DESCR(objects[otmp->otyp])));
|
||||||
|
|||||||
Reference in New Issue
Block a user