Verify bounds for linked lists
This commit is contained in:
parent
5e39abf730
commit
25424a01db
2 changed files with 9 additions and 4 deletions
2
advent.h
2
advent.h
|
@ -165,7 +165,7 @@ struct game_t {
|
||||||
loc_t dloc[NDWARVES + 1]; // location of dwarves, initially hard-wired in
|
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 odloc[NDWARVES + 1]; // prior loc of each dwarf, initially garbage
|
||||||
loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE)
|
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
|
loc_t place[NOBJECTS + 1]; // location of object
|
||||||
long hinted[NHINTS]; // hinted[i] = true iff hint i has been used.
|
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
|
long hintlc[NHINTS]; // hintlc[i] = how long at LOC with cond bit i
|
||||||
|
|
11
saveresume.c
11
saveresume.c
|
@ -185,7 +185,7 @@ bool is_valid(struct game_t valgame)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that properties of objects aren't beyond expected */
|
/* 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) {
|
if (valgame.prop[obj] < STATE_NOTFOUND || valgame.prop[obj] > 1) {
|
||||||
switch (obj) {
|
switch (obj) {
|
||||||
case RUG:
|
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++) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue