From f0dc3d3b7c8c169ae0581b7e9c5e209dd28c682a Mon Sep 17 00:00:00 2001 From: NHOrus Date: Sun, 13 Aug 2017 15:16:09 +0100 Subject: [PATCH] Verify sanity of location arrays --- saveresume.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/saveresume.c b/saveresume.c index 8897945..ecfc643 100644 --- a/saveresume.c +++ b/saveresume.c @@ -144,7 +144,21 @@ bool is_valid(struct game_t valgame) valgame.oldloc < -1 || valgame.oldloc > NLOCATIONS) { return false; } + /* Bounds check for location arrays + */ + for (int i = 0; i <= NDWARVES; i++) { + if (valgame.dloc[i] < -1 || valgame.dloc[i] > NLOCATIONS || + valgame.odloc[i] < -1 || valgame.odloc[i] > NLOCATIONS) { + return false; + } + } + for (int i = 0; i <= NOBJECTS; i++) { + if (valgame.place[i] < -1 || valgame.place[i] > NLOCATIONS || + valgame.fixed[i] < -1 || valgame.fixed[i] > NLOCATIONS) { + return false; + } + } return true; } -- 2.31.1