Mercurial > hg > early-roguelike
comparison rogue3/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 | 527e2150eaf0 |
children | 7f8f43943b1f |
comparison
equal
deleted
inserted
replaced
82:f11eeafc6568 | 83:09db0cf536af |
---|---|
763 { | 763 { |
764 int i; | 764 int i; |
765 | 765 |
766 rs_read_int(savef, &i); | 766 rs_read_int(savef, &i); |
767 | 767 |
768 if (!encerror()) | 768 if (!encerror()) { |
769 *rp = &rooms[i]; | 769 if (i >= 0 && i < MAXROOMS) |
770 *rp = &rooms[i]; | |
771 else | |
772 *rp = NULL; | |
773 } | |
770 } | 774 } |
771 | 775 |
772 void | 776 void |
773 rs_write_object(FILE *savef, struct object *o) | 777 rs_write_object(FILE *savef, struct object *o) |
774 { | 778 { |