Mercurial > hg > early-roguelike
comparison srogue/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 | 3aa87373c908 |
children | 94a0d9dd5ce1 |
comparison
equal
deleted
inserted
replaced
82:f11eeafc6568 | 83:09db0cf536af |
---|---|
1126 { | 1126 { |
1127 int i; | 1127 int i; |
1128 | 1128 |
1129 rs_read_int(inf, &i); | 1129 rs_read_int(inf, &i); |
1130 | 1130 |
1131 *rp = &rooms[i]; | 1131 if (i >= 0 && i < MAXROOMS) |
1132 *rp = &rooms[i]; | |
1133 else | |
1134 *rp = NULL; | |
1132 | 1135 |
1133 return(READSTAT); | 1136 return(READSTAT); |
1134 } | 1137 } |
1135 | 1138 |
1136 int | 1139 int |