From 97a1724f177841ca33a2196c088513c8bc172a1d Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 17 Jun 2023 20:28:07 -0700 Subject: [PATCH] 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. --- src/fountain.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fountain.c b/src/fountain.c index 13096f095..de6094619 100644 --- a/src/fountain.c +++ b/src/fountain.c @@ -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])));