+ /* Bounds check for location arrays */
+ for (int i = 0; i <= NDWARVES; i++) {
+ if (valgame.dwarves[i].loc < -1 || valgame.dwarves[i].loc > NLOCATIONS ||
+ valgame.dwarves[i].oldloc < -1 || valgame.dwarves[i].oldloc > NLOCATIONS) {
+ return false; // LCOV_EXCL_LINE
+ }
+ }
+
+ for (int i = 0; i <= NOBJECTS; i++) {
+ if (valgame.objects[i].place < -1 || valgame.objects[i].place > NLOCATIONS ||
+ valgame.objects[i].fixed < -1 || valgame.objects[i].fixed > NLOCATIONS) {
+ return false; // LCOV_EXCL_LINE
+ }
+ }
+
+ /* Bounds check for dwarves */
+ if (valgame.dtotal < 0 || valgame.dtotal > NDWARVES ||
+ valgame.dkill < 0 || valgame.dkill > NDWARVES) {
+ return false; // LCOV_EXCL_LINE
+ }
+
+ /* Validate that we didn't die too many times in save */
+ if (valgame.numdie >= NDEATHS) {
+ return false; // LCOV_EXCL_LINE
+ }
+
+ /* Recalculate tally, throw the towel if in disagreement */
+ int temp_tally = 0;
+ for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
+ if (objects[treasure].is_treasure) {
+ if (PROP_IS_NOTFOUND2(valgame, treasure)) {
+ ++temp_tally;
+ }
+ }
+ }
+ if (temp_tally != valgame.tally) {
+ return false; // LCOV_EXCL_LINE
+ }
+
+ /* Check that properties of objects aren't beyond expected */
+ for (obj_t obj = 0; obj <= NOBJECTS; obj++) {
+ if (PROP_IS_INVALID(valgame.objects[obj].prop)) {
+ return false; // LCOV_EXCL_LINE
+ }
+ }
+
+ /* Check that values in linked lists for objects in locations are inside bounds */
+ for (loc_t loc = LOC_NOWHERE; loc <= NLOCATIONS; loc++) {
+ if (valgame.locs[loc].atloc < NO_OBJECT || valgame.locs[loc].atloc > NOBJECTS * 2) {
+ return false; // LCOV_EXCL_LINE
+ }
+ }
+ for (obj_t obj = 0; obj <= NOBJECTS * 2; obj++ ) {
+ if (valgame.link[obj] < NO_OBJECT || valgame.link[obj] > NOBJECTS * 2) {
+ return false; // LCOV_EXCL_LINE
+ }
+ }
+
+ return true;