From 93bcfeac29348eab9b30eac0d2f6e29fbd0e13db Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 23 Dec 2023 22:55:14 -0500 Subject: [PATCH] static analyzer bit for artifact.c src/artifact.c(1589): warning C6011: Dereferencing NULL pointer 'magr'. The 'struct monst *magr' parameter to artifact_hit() can be Null if 'mdef' is youmonst. mdef is nonnull. --- include/extern.h | 2 +- src/artifact.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/extern.h b/include/extern.h index 5538d1a86..bf65ddc9c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -155,7 +155,7 @@ extern boolean undiscovered_artifact(xint16); extern int disp_artifact_discoveries(winid); extern void dump_artifact_info(winid); extern boolean artifact_hit(struct monst *, struct monst *, struct obj *, - int *, int); + int *, int) NONNULLARG2; extern int doinvoke(void); extern boolean finesse_ahriman(struct obj *); extern int arti_speak(struct obj *); diff --git a/src/artifact.c b/src/artifact.c index a63f6a0fd..49a357913 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -1586,6 +1586,7 @@ artifact_hit( if (youattack) { healup(drain, 0, FALSE, FALSE); } else { + assert(magr != 0); magr->mhp += drain; if (magr->mhp > magr->mhpmax) magr->mhp = magr->mhpmax;