mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
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:
parent
2c5f1e33fe
commit
cdfae7d453
1 changed files with 1 additions and 1 deletions
|
|
@ -42,7 +42,7 @@ void carve(int x, int y) {
|
||||||
int dirs[] = {0, 1, 2, 3};
|
int dirs[] = {0, 1, 2, 3};
|
||||||
// Fisher-Yates shuffle
|
// Fisher-Yates shuffle
|
||||||
for (int i = 3; i > 0; i--) {
|
for (int i = 3; i > 0; i--) {
|
||||||
int j = mulberry32() % (i + 1);
|
int j = (unsigned)mulberry32() % (i + 1);
|
||||||
int tmp = dirs[i];
|
int tmp = dirs[i];
|
||||||
dirs[i] = dirs[j];
|
dirs[i] = dirs[j];
|
||||||
dirs[j] = tmp;
|
dirs[j] = tmp;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue