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.
This commit is contained in:
Stéphane Travostino 2025-12-14 10:15:04 +01:00
parent 2c5f1e33fe
commit cdfae7d453

View file

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