Verify sanity of location arrays
authorNHOrus <jy6x2b32pie9@yahoo.com>
Sun, 13 Aug 2017 14:16:09 +0000 (15:16 +0100)
committerNHOrus <jy6x2b32pie9@yahoo.com>
Sun, 13 Aug 2017 14:16:09 +0000 (15:16 +0100)
saveresume.c

index 889794596ae2325e8500e909e7765f9f567b0a32..ecfc643d8f772ad82581b5cf9bcaa688f710c0c4 100644 (file)
@@ -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;
 }