From 2da740a5eb1ca92296e70302978061766ddbd679 Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 9 Sep 2025 21:57:58 +0200 Subject: [PATCH] fix: add out of bounds checks to `tetris_intersect` --- src/tetris.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tetris.c b/src/tetris.c index 79e72e7..f826798 100644 --- a/src/tetris.c +++ b/src/tetris.c @@ -62,7 +62,11 @@ int tetris_intersect(const u8 *restrict const *restrict rows, u8 tetromino, uint uint *pos = (uint[8]){x, y, x, y, x, y, x, y}; uint *end = pos + 8; tetris_get_blocks(tetromino, pos); - while (pos < end && !rows[*(pos + 1)][*pos]) pos += 2; + for (; pos < end; pos += 2) { + if (*(pos + 0) >= TET_WIDTH) break; + if (*(pos + 1) >= TET_HEIGHT) break; + if (rows[*(pos + 1)][*pos]) break; + } return pos < end; }