Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

NumBlocks: two fixes found by the fuzz test

Mason Chen9f647953bbde
diff --git a/games/numblocks/src/render.c b/games/numblocks/src/render.c
index b97e388f..c352a7b7 100644
--- a/games/numblocks/src/render.c
+++ b/games/numblocks/src/render.c
@@ -314,7 +314,9 @@ static uint16_t trace(float dx, float dy, float dz) {
int x = cam_x, y = cam_y, z = cam_z;
int sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, sz = dz > 0 ? 1 : -1;
/* signed inverses: the ray reaches plane x = X at t = (X - ox) * ivx */
- float ivx = dx != 0 ? 1 / dx : 1e9f, ivy = dy != 0 ? 1 / dy : 1e9f, ivz = dz != 0 ? 1 / dz : 1e9f;
+ /* (a 0 component steps the negative way: its inverse must be "minus infinity", or the
+ * boundaries behind the camera would come first) */
+ float ivx = dx != 0 ? 1 / dx : -1e9f, ivy = dy != 0 ? 1 / dy : -1e9f, ivz = dz != 0 ? 1 / dz : -1e9f;
float idx = fabsf(ivx), idy = fabsf(ivy), idz = fabsf(ivz);
int bx = dx > 0, by = dy > 0, bz = dz > 0;
float tx = (x + bx - ox) * ivx, ty = (y + by - oy) * ivy, tz = (z + bz - oz) * ivz;
diff --git a/games/numblocks/src/save.c b/games/numblocks/src/save.c
index 2e2daa95..d59cfa30 100644
--- a/games/numblocks/src/save.c
+++ b/games/numblocks/src/save.c
@@ -84,7 +84,8 @@ bool load_world(void) {
void new_world(int64_t seed, int mode) {
plat_remove_prefix(WORLD);
uint32_t tl;
- memset(tiles_data(&tl), 0, tl);
+ void *t = tiles_data(&tl); /* (first: the length is only known after the call) */
+ memset(t, 0, tl);
memset(ents, 0, sizeof ents);
world_seed = seed;
game_time = 0;