From 294ce9b59d2800697cc4ddf58ca1f1faaf99fec6 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 16 Dec 2023 12:37:49 -0500 Subject: [PATCH] reinstate removal of mon guard from is_safemon() callers were checked: domove_attackmon_at(mtmp, x, y, displaceu) has mtmp declared nonnull; there are dereferences of mtmp in the first line of code in the function. In domove_core(): The 1st occurrence of is_safemon(mtmp) is guarded by if (mtmp) { }. The 2nd occurrence of is_safemon(mtmp) is inside an if (mtmp) { } block. The 3rd occurrence of is_safemon(mtmp) was just remediated by 987be7e8. In lookaround(): The only occurrence of is_safemon(mtmp) is inside an if ((mtmp = m_at(x, y)) != 0 [...] { } block. In do_attack(mtmp), in uhitm.c: The parameter is declared NONNULLARG1, and the 1st line of code contains a dereference with mtmp->data, which would segfault if mtmp were NULL. --- include/display.h | 2 +- src/hack.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/display.h b/include/display.h index 20c6cead6..ee4958905 100644 --- a/include/display.h +++ b/include/display.h @@ -157,7 +157,7 @@ * definition here is convenient. No longer limited to pets. */ #define _is_safemon(mon) \ - (flags.safe_dog && (mon) && (mon)->mpeaceful && canspotmon(mon) \ + (flags.safe_dog && (mon)->mpeaceful && canspotmon(mon) \ && !Confusion && !Hallucination && !Stunned) /* diff --git a/src/hack.c b/src/hack.c index 1f18b41fe..1c0f6c4fe 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1768,6 +1768,7 @@ domove_attackmon_at( coordxy x, coordxy y, boolean *displaceu) { + /* assert(mtmp != NULL) */ /* only attack if we know it's there * or if we used the 'F' command to fight blindly * or if it hides_under, in which case we call do_attack() to print