ref: 49d28f2204dfbb21156d98b0313399c8126b59e0
parent: 42cbd7688a7f05e0a5d56a603a04293307c1e1b2
author: Simon Tatham <anakin@pobox.com>
date: Thu Oct 21 16:39:09 EDT 2021
Tents: fix bias in tent placement. In the very first stage of game generation, we're supposed to pick 1/5 of the grid squares to put tents in, in a uniformly random manner. It failed to be uniform, because I had the wrong limit in random_upto - but it was too small rather than too large, so it never overran the buffer in a way that something like ASan or valgrind would have caught.
--- a/tents.c
+++ b/tents.c
@@ -998,7 +998,7 @@
int dy, dx;
bool ok = true;
- which = i + random_upto(rs, j);
+ which = i + random_upto(rs, w*h - i);
tmp = order[which];
order[which] = order[i];
order[i] = tmp;