From e6493b4184f353a2c0d0adf2a49cbe9365418102 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Wed, 17 May 2017 09:12:52 +1000 Subject: [PATCH] Fix an off-by-one bug in the macros GALAXY_MAP_RIGHT and GALAXY_MAP_DOWN This bug has been present since commit e2dbe549b2af7dfd909480fee4d97cf694b0d1fc dated Sat Jul 16 13:34:13 2011 +1000: almost six years ago! --- src/move.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/move.c b/src/move.c index 0ac40ff..bf9d649 100644 --- a/src/move.c +++ b/src/move.c @@ -37,10 +37,10 @@ // Calculate positions near (x,y), taking the edge of the galaxy into account -#define GALAXY_MAP_LEFT(x, y) (((x) <= 0) ? MAP_EMPTY : galaxy_map[(x) - 1][(y)]) -#define GALAXY_MAP_RIGHT(x, y) (((x) >= MAX_X) ? MAP_EMPTY : galaxy_map[(x) + 1][(y)]) -#define GALAXY_MAP_UP(x, y) (((y) <= 0) ? MAP_EMPTY : galaxy_map[(x)][(y) - 1]) -#define GALAXY_MAP_DOWN(x, y) (((y) >= MAX_Y) ? MAP_EMPTY : galaxy_map[(x)][(y) + 1]) +#define GALAXY_MAP_LEFT(x, y) (((x) <= 0) ? MAP_EMPTY : galaxy_map[(x) - 1][(y)]) +#define GALAXY_MAP_RIGHT(x, y) (((x) >= (MAX_X - 1)) ? MAP_EMPTY : galaxy_map[(x) + 1][(y)]) +#define GALAXY_MAP_UP(x, y) (((y) <= 0) ? MAP_EMPTY : galaxy_map[(x)][(y) - 1]) +#define GALAXY_MAP_DOWN(x, y) (((y) >= (MAX_Y - 1)) ? MAP_EMPTY : galaxy_map[(x)][(y) + 1]) #define assign_vals(x, y, left, right, up, down) \ do { \