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:
PatR
2023-06-17 20:28:07 -07:00
parent 8b9a93f797
commit 97a1724f17

View File

@@ -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 */
/* NetHack may be freely redistributed. See license for details. */
@@ -590,13 +590,13 @@ drinksink(void)
}
break;
case 4:
do {
for (;;) {
otmp = mkobj(POTION_CLASS, FALSE);
if (otmp->otyp == POT_WATER) {
obfree(otmp, (struct obj *) 0);
otmp = (struct obj *) 0;
}
} while (!otmp);
if (otmp->otyp != POT_WATER)
break;
/* reject water and try again */
obfree(otmp, (struct obj *) 0);
}
otmp->cursed = otmp->blessed = 0;
pline("Some %s liquid flows from the faucet.",
Blind ? "odd" : hcolor(OBJ_DESCR(objects[otmp->otyp])));