From caa8aa7f60ebb8eb7d5f1e5fa1ddfdef9f821a0c Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 16 Dec 2023 12:55:09 -0500 Subject: [PATCH] reinstate obj guard on _see_with_infrared macro Checking the callers: newsym() the use of see_with_infrared() is guarded by } else if ((mon = m_at(x, y)) != 0 [...] do_mgivenname() the use of see_with_infrared is guarded by !mtmp: && (!mtmp || (!sensemon(mtmp) && (!(cansee(cx, cy) || see_with_infrared(mtmp)) howmonseen(mon) dereferences mon in other places, so it would segfault if mon were NULL; howmonseen has NONNULLARG1. --- include/display.h | 2 +- src/vision.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/display.h b/include/display.h index ee4958905..b97b1d8e4 100644 --- a/include/display.h +++ b/include/display.h @@ -104,7 +104,7 @@ * canseemon() or canspotmon() which already check that. */ #define _see_with_infrared(mon) \ - (!Blind && Infravision && mon && infravisible(mon->data) \ + (!Blind && Infravision && infravisible(mon->data) \ && couldsee(mon->mx, mon->my)) /* diff --git a/src/vision.c b/src/vision.c index 341ef9c57..d670c3a38 100644 --- a/src/vision.c +++ b/src/vision.c @@ -2131,6 +2131,7 @@ howmonseen(struct monst *mon) int xraydist = (u.xray_range < 0) ? -1 : (u.xray_range * u.xray_range); unsigned how_seen = 0; /* result */ + /* assert(mon != NULL) */ /* normal vision; cansee is true for both normal and astral vision, but couldsee it not true for astral vision */