Fix some terribly depressing corruption during restore.

In rogue5/state.c, rs_read_daemons() zeroes out the argument and delay
if the daemon slot is empty.  Unfortunately that code ended up on the
wrong side of the brace that closes the for loop, so instead of running
after each daemon, it got run once after the loop exited, when the
index was of course out of bounds.

This tended to manifest, when compiled with -O2, by overwriting hw and
setting it to NULL.  When inventory() next ran, hw would be passed to
wgetch(), which returns ERR when it gets a NULL argument.  This made
md_readchar() think something was wrong and autosave the game.

Upon investigation, rogue3 was found to commit the same mistake.
rogue4 and srogue don't zero the data.  arogue5 already does it
properly.

Someday I am going to run all this through Valgrind.  Someday when I
am a kinder person who will not be driven to invoke hordes of trolls
and centaurs upon the original authors.
This commit is contained in:
John "Elwin" Edwards 2014-01-08 16:44:16 -05:00
parent 46568d24a4
commit 082cd54126
2 changed files with 13 additions and 13 deletions

View file

@ -681,14 +681,13 @@ rs_read_daemons(FILE *savef, struct delayed_action *dlist, int cnt)
default:dlist[i].d_func = NULL;
break;
}
if (dlist[i].d_func == NULL)
{
dlist[i].d_type = 0;
dlist[i].d_arg = 0;
dlist[i].d_time = 0;
}
}
if (dlist[i].d_func == NULL)
{
dlist[i].d_type = 0;
dlist[i].d_arg = 0;
dlist[i].d_time = 0;
}
}
void

View file

@ -660,14 +660,15 @@ rs_read_daemons(FILE *savef, struct delayed_action *dlist, int cnt)
default:dlist[i].d_func = NULL;
break;
}
if (dlist[i].d_func == NULL)
{
dlist[i].d_type = 0;
dlist[i].d_arg = 0;
dlist[i].d_time = 0;
}
}
if (dlist[i].d_func == NULL)
{
dlist[i].d_type = 0;
dlist[i].d_arg = 0;
dlist[i].d_time = 0;
}
}
void