From d6f036f3298e19fd9c6443e45957fd9dc563da46 Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 22 Dec 2023 17:18:40 -0500 Subject: [PATCH] static analyzer bit in timeout.c src/timeout.c(2033): warning: Reading invalid data from 'gl.level.locations'. Analyzer couldn't tell that isok(x, y) had validated x and y to be safe indexes into gl.level.locations[x][y]. Code it a bit differently, so that the static analyzer becomes perfectly aware that the indexes are, indeed, in range. --- src/timeout.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/timeout.c b/src/timeout.c index 24966f8f9..14a5f8d13 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -2026,12 +2026,15 @@ timer_sanity_check(void) coordxy x = (coordxy) ((where >> 16) & 0xFFFF), y = (coordxy) (where & 0xFFFF); - if (!isok(x, y)) { + /* instead of isok(x,y), so static analyzer follows along better */ + if (x > 0 && x < COLNO && y >= 0 && y < ROWNO) { + if (curr->func_index == MELT_ICE_AWAY && !is_ice(x, y)) + impossible( + "timer sanity: melt timer %lu on non-ice %d <%d,%d>", + curr->tid, levl[x][y].typ, x, y); + } else { impossible("timer sanity: spot timer %lu at <%d,%d>", curr->tid, x, y); - } else if (curr->func_index == MELT_ICE_AWAY && !is_ice(x, y)) { - impossible("timer sanity: melt timer %lu on non-ice %d <%d,%d>", - curr->tid, levl[x][y].typ, x, y); } } }