diff --git a/advent.h b/advent.h index 6d83807..17ae719 100644 --- a/advent.h +++ b/advent.h @@ -165,7 +165,7 @@ struct game_t { loc_t dloc[NDWARVES + 1]; // location of dwarves, initially hard-wired in loc_t odloc[NDWARVES + 1]; // prior loc of each dwarf, initially garbage loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE) - long link[NOBJECTS * 2 + 1]; // object-list links + obj_t link[NOBJECTS * 2 + 1]; // object-list links loc_t place[NOBJECTS + 1]; // location of object long hinted[NHINTS]; // hinted[i] = true iff hint i has been used. long hintlc[NHINTS]; // hintlc[i] = how long at LOC with cond bit i diff --git a/saveresume.c b/saveresume.c index 6027096..4378324 100644 --- a/saveresume.c +++ b/saveresume.c @@ -185,7 +185,7 @@ bool is_valid(struct game_t valgame) } /* Check that properties of objects aren't beyond expected */ - for (int obj = 0; obj <= NOBJECTS; obj++) { + for (obj_t obj = 0; obj <= NOBJECTS; obj++) { if (valgame.prop[obj] < STATE_NOTFOUND || valgame.prop[obj] > 1) { switch (obj) { case RUG: @@ -210,9 +210,14 @@ bool is_valid(struct game_t valgame) } } - /* Check that we have objects at locations */ + /* Check that values in linked lists for objects in locations are inside bounds */ for (loc_t loc = LOC_NOWHERE; loc <= NLOCATIONS; loc++) { - if (valgame.atloc[loc] < NO_OBJECT || valgame.atloc[loc] > NOBJECTS * 2 + 1) { + if (valgame.atloc[loc] < NO_OBJECT || valgame.atloc[loc] > NOBJECTS * 2) { + return false; + } + } + for (obj_t obj = 0; obj <= NOBJECTS * 2; obj++ ) { + if (valgame.link[obj] < NO_OBJECT || valgame.link[obj] > NOBJECTS * 2) { return false; } }