From cdfae7d4537476469e070564a62f980892d2d551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Travostino?= Date: Sun, 14 Dec 2025 10:15:04 +0100 Subject: [PATCH] apps/maze: fix possible stack overflow The original code this app is inspired from uses rand(), which returns a number >= 0. mulberry32() on the other hand can return a negative number, in which case will overflow the accesses in the dirs array. Fix that by forcing the result to be unsigned. --- apps/maze/maze.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/maze/maze.c b/apps/maze/maze.c index d2d10a6..1c2edcd 100644 --- a/apps/maze/maze.c +++ b/apps/maze/maze.c @@ -42,7 +42,7 @@ void carve(int x, int y) { int dirs[] = {0, 1, 2, 3}; // Fisher-Yates shuffle for (int i = 3; i > 0; i--) { - int j = mulberry32() % (i + 1); + int j = (unsigned)mulberry32() % (i + 1); int tmp = dirs[i]; dirs[i] = dirs[j]; dirs[j] = tmp;