From 94b59cbd3580beaeeb5c4caa5124d356429ef5e3 Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 26 Dec 2023 23:42:23 -0500 Subject: [PATCH] static analyzer bit for read.c src/read.c(2889): warning: Dereferencing NULL pointer 'sobj'. The analyzer doesn't know that the one caller that passes a NULL sobj argument, angrygods(), checks !Punished before doing so. Use a NULL guard before dereferencing sobj so that it doesn't matter anyway. --- src/read.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/read.c b/src/read.c index 94185f453..4fa79f6d1 100644 --- a/src/read.c +++ b/src/read.c @@ -2878,15 +2878,19 @@ do_genocide( void punish(struct obj* sobj) { + /* angrygods() calls this with NULL sobj arg */ struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL) ? sobj : (struct obj *) 0; + /* analyzer doesn't know that the one caller that passes a NULL + * sobj (angrygods) checks !Punished first, so add a guard */ + int cursed_levy = (sobj && sobj->cursed) ? 1 : 0; /* KMH -- Punishment is still okay when you are riding */ if (!reuse_ball) You("are being punished for your misbehavior!"); if (Punished) { Your("iron ball gets heavier."); - uball->owt += IRON_BALL_W_INCR * (1 + sobj->cursed); + uball->owt += IRON_BALL_W_INCR * (1 + cursed_levy); return; } if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)