diff arogue5/state.c @ 83:09db0cf536af

Properly handle invalid room references in savefiles. In all games, rs_write_room_reference() stored -1 for a nonexistent room, but rs_read_room_reference() did not check for out-of-bounds values, leading to pointers to rooms[-1], which sometimes caused crashes. rs_read_room_reference() has now been modified to use NULL instead. Some of the games required further changes to replace NULL with the pointer to the actual room. Others are capable of handling NULL for objects not in any room.
author John "Elwin" Edwards
date Thu, 08 Aug 2013 12:41:35 -0700
parents 19903deed392
children 5f51f7d9805f
line wrap: on
line diff
--- a/arogue5/state.c	Tue Aug 06 19:02:58 2013 -0700
+++ b/arogue5/state.c	Thu Aug 08 12:41:35 2013 -0700
@@ -1661,7 +1661,10 @@
 
     rs_read_int(inf, &i);
 
-    *rp = &rooms[i];
+    if (i >= 0 && i < MAXROOMS)
+        *rp = &rooms[i];
+    else
+        *rp = NULL;
             
     return(READSTAT);
 }