From 4d6e3326bba24ad259eae0ea06a12790560a45b4 Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 23 Nov 2018 22:17:09 -0500 Subject: [PATCH] Revert "Instance variable work." This reverts commit 14bf74c8629fe1731cb0dc72afa263256980f89f. --- include/decl.h | 5 ----- src/decl.c | 5 ----- src/save.c | 24 ++++++++++++++---------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/include/decl.h b/include/decl.h index e8a8dfab5..e0597efe3 100644 --- a/include/decl.h +++ b/include/decl.h @@ -460,11 +460,6 @@ 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 c517edaa5..a6c651965 100644 --- a/src/decl.c +++ b/src/decl.c @@ -344,10 +344,6 @@ 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 */ @@ -374,7 +370,6 @@ 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 de2c99b74..bca03c49e 100644 --- a/src/save.c +++ b/src/save.c @@ -71,6 +71,9 @@ 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() { @@ -210,8 +213,8 @@ dosave0() store_version(fd); store_savefileinfo(fd); store_plname_in_file(fd); - iv.ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - iv.usteed_id = (u.usteed ? u.usteed->m_id : 0); + ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + 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); @@ -333,10 +336,10 @@ register int fd, mode; sizeof(struct spell) * (MAXSPELL + 1)); save_artifacts(fd); save_oracles(fd, mode); - 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); + if (ustuck_id) + bwrite(fd, (genericptr_t) &ustuck_id, sizeof ustuck_id); + if (usteed_id) + bwrite(fd, (genericptr_t) &usteed_id, sizeof usteed_id); bwrite(fd, (genericptr_t) pl_character, sizeof pl_character); bwrite(fd, (genericptr_t) pl_fruit, sizeof pl_fruit); savefruitchn(fd, mode); @@ -366,6 +369,7 @@ void savestateinlock() { int fd, hpid; + static boolean havestate = TRUE; char whynot[BUFSZ]; /* When checkpointing is on, the full state needs to be written @@ -379,7 +383,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 || iv.havestate) { + if (flags.ins_chkpt || 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 @@ -417,13 +421,13 @@ savestateinlock() store_savefileinfo(fd); store_plname_in_file(fd); - iv.ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); - iv.usteed_id = (u.usteed ? u.usteed->m_id : 0); + ustuck_id = (u.ustuck ? u.ustuck->m_id : 0); + usteed_id = (u.usteed ? u.usteed->m_id : 0); savegamestate(fd, WRITE_SAVE); } bclose(fd); } - iv.havestate = flags.ins_chkpt; + havestate = flags.ins_chkpt; } #endif