]> granicus.if.org Git - nethack/commitdiff
another static analyzer bit - cast_protection()
authorPatR <rankin@nethack.org>
Sat, 14 Jan 2023 07:55:37 +0000 (23:55 -0800)
committerPatR <rankin@nethack.org>
Sat, 14 Jan 2023 07:55:37 +0000 (23:55 -0800)
The code tested u.uswallow and then accessed u.ustuck.  Under normal
circumstances that works fine but it could be a problem if the two
fields got out of synch.  This ought to fix the analyzer complaint
and avoid any trouble with mondata access.

src/spell.c

index f4c2e8a024e775f71bececdb8109dd9f61d4dea9..a481aea86942d586d6cc0eef7cb02d03d8674f22 100644 (file)
@@ -858,11 +858,11 @@ cast_protection(void)
                 struct permonst *pm = u.ustuck ? u.ustuck->data : 0;
 
                 rmtyp = levl[u.ux][u.uy].typ;
-                atmosphere = u.uswallow
+                atmosphere = (pm && u.uswallow)
                                 ? ((pm == &mons[PM_FOG_CLOUD]) ? "mist"
-                                   : is_whirly(u.ustuck->data) ? "maelstrom"
+                                   : is_whirly(pm) ? "maelstrom"
                                      : enfolds(pm) ? "folds"
-                                       : is_animal(u.ustuck->data) ? "maw"
+                                       : is_animal(pm) ? "maw"
                                          : "ooze")
                                 : (u.uinwater ? hliquid("water")
                                    : (rmtyp == CLOUD) ? "cloud"