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.
This commit is contained in:
nhmall
2023-12-26 23:42:23 -05:00
parent 90d1e30ebd
commit 94b59cbd35
+5 -1
View File
@@ -2878,15 +2878,19 @@ do_genocide(
void void
punish(struct obj* sobj) punish(struct obj* sobj)
{ {
/* angrygods() calls this with NULL sobj arg */
struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL) struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL)
? sobj : (struct obj *) 0; ? 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 */ /* KMH -- Punishment is still okay when you are riding */
if (!reuse_ball) if (!reuse_ball)
You("are being punished for your misbehavior!"); You("are being punished for your misbehavior!");
if (Punished) { if (Punished) {
Your("iron ball gets heavier."); Your("iron ball gets heavier.");
uball->owt += IRON_BALL_W_INCR * (1 + sobj->cursed); uball->owt += IRON_BALL_W_INCR * (1 + cursed_levy);
return; return;
} }
if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data) if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)