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.
This commit is contained in:
nhmall
2023-12-22 17:18:40 -05:00
parent fcc91cec94
commit d6f036f329

View File

@@ -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);
}
}
}