diff --git a/include/decl.h b/include/decl.h index e0597efe3..e8a8dfab5 100644 --- a/include/decl.h +++ b/include/decl.h @@ -460,6 +460,11 @@ struct instance_variables { boolean m_using; /* kludge to use mondided instead of killed */ /* pickup.c */ int oldcap; /* last encumberance */ + /* save.c */ + boolean havestate; + unsigned ustuck_id; /* need to preserve during save */ + unsigned usteed_id; /* need to preserve during save */ + /* trap.c */ int force_mintrap; /* mintrap() should take a flags argument, but for time being we use this */ diff --git a/src/decl.c b/src/decl.c index a6c651965..c517edaa5 100644 --- a/src/decl.c +++ b/src/decl.c @@ -344,6 +344,10 @@ const struct instance_variables iv_init = { FALSE, /* m_using */ /* pickup.c */ 0, /* oldcap */ + /* save.c */ + TRUE, /* havestate*/ + 0, /* ustuck_id */ + 0, /* usteed_id */ /* trap.c */ 0, /* force_mintrap */ /* u_init.c */ @@ -370,6 +374,7 @@ instance_variable_init() iv = iv_init; nhassert(iv_init.magic == IVMAGIC); + nhassert(iv.havestate == TRUE); sfcap = default_sfinfo; sfrestinfo = default_sfinfo; diff --git a/src/save.c b/src/save.c index bca03c49e..de2c99b74 100644 --- a/src/save.c +++ b/src/save.c @@ -71,9 +71,6 @@ static struct save_procs { #define HUP #endif -/* need to preserve these during save to avoid accessing freed memory */ -static unsigned ustuck_id = 0, usteed_id = 0; - int dosave() { @@ -213,8 +210,8 @@ dosave0() store_version(fd); store_savefileinfo(fd); store_plname_in_file(fd); - ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - usteed_id = (u.usteed ? u.usteed->m_id : 0); + iv.ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + iv.usteed_id = (u.usteed ? u.usteed->m_id : 0); savelev(fd, ledger_no(&u.uz), WRITE_SAVE | FREE_SAVE); savegamestate(fd, WRITE_SAVE | FREE_SAVE); @@ -336,10 +333,10 @@ register int fd, mode; sizeof(struct spell) * (MAXSPELL + 1)); save_artifacts(fd); save_oracles(fd, mode); - if (ustuck_id) - bwrite(fd, (genericptr_t) &ustuck_id, sizeof ustuck_id); - if (usteed_id) - bwrite(fd, (genericptr_t) &usteed_id, sizeof usteed_id); + if (iv.ustuck_id) + bwrite(fd, (genericptr_t) &iv.ustuck_id, sizeof iv.ustuck_id); + if (iv.usteed_id) + bwrite(fd, (genericptr_t) &iv.usteed_id, sizeof iv.usteed_id); bwrite(fd, (genericptr_t) pl_character, sizeof pl_character); bwrite(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); savefruitchn(fd, mode); @@ -369,7 +366,6 @@ void savestateinlock() { int fd, hpid; - static boolean havestate = TRUE; char whynot[BUFSZ]; /* When checkpointing is on, the full state needs to be written @@ -383,7 +379,7 @@ savestateinlock() * noop pid rewriting will take place on the first "checkpoint" after * the game is started or restored, if checkpointing is off. */ - if (flags.ins_chkpt || havestate) { + if (flags.ins_chkpt || iv.havestate) { /* save the rest of the current game state in the lock file, * following the original int pid, the current level number, * and the current savefile name, which should not be subject @@ -421,13 +417,13 @@ savestateinlock() store_savefileinfo(fd); store_plname_in_file(fd); - ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - usteed_id = (u.usteed ? u.usteed->m_id : 0); + iv.ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + iv.usteed_id = (u.usteed ? u.usteed->m_id : 0); savegamestate(fd, WRITE_SAVE); } bclose(fd); } - havestate = flags.ins_chkpt; + iv.havestate = flags.ins_chkpt; } #endif