]> granicus.if.org Git - nethack/commitdiff
stale spellbook pointer
authornethack.rankin <nethack.rankin>
Sun, 20 Jan 2002 09:53:36 +0000 (09:53 +0000)
committernethack.rankin <nethack.rankin>
Sun, 20 Jan 2002 09:53:36 +0000 (09:53 +0000)
     If you get interrupted while reading a spellbook and then
the book gets destroyed or you change levels, the object pointer
remembered for the book will be invalid and could accidentally
match one subsequently allocated to some other book.  That would
result in "you continue your efforts to memorize the spell" when
starting to read that other book; it would also end up bypassing
the reading difficulty check and reuse the old book's delay counter.

     I don't remember who reported this.  It was quite some time
ago and I have an abandoned patch dated last March from when I
first started to fix it.

Files patched:
  include/extern.h
  src/save.c, shk.c, spell.c

doc/fixes33.2
include/extern.h
src/save.c
src/shk.c
src/spell.c

index 9bea526d9879147483b40eb623c85610eb233d75..d6bf5da2ad30b7aef7654a101ce6f02e66a86d86 100644 (file)
@@ -493,6 +493,8 @@ add wizard #poly and #levelchange (originally levelgain; Dylan O'Donnell),
 add Jason Short's additional lenses use patch
 add new Gnomish Mines levels from Kelly Bailey's patch
 jousting by players wielding a lance while riding
+when reading spellbooks, don't "continue studying" wrong book if original one
+       gets destroyed after previous reading attempt has been interrupted
 
 
 Platform- and/or Interface-Specific New Features
index 6a9ce1b306d710b6f08cc790664f0f6d387f1089..f786e60dbc0cdfa577fb482f0a2c1677c2d52d46 100644 (file)
@@ -1808,6 +1808,7 @@ E boolean FDECL(load_special, (const char *));
 E int NDECL(learn);
 #endif
 E int FDECL(study_book, (struct obj *));
+E void FDECL(book_disappears, (struct obj *));
 E void FDECL(book_substitution, (struct obj *,struct obj *));
 E void NDECL(age_spells);
 E int NDECL(docast);
index 1e6720addfe23799b19afb10645d1f14d4ef8e8d..f70fbfbdf9fbd8ec572a6cb1fa45645ea76ca6d1 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)save.c     3.3     2000/07/27      */
+/*     SCCS Id: @(#)save.c     3.3     2002/01/19      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -840,7 +840,8 @@ register struct obj *otmp;
            if (Has_contents(otmp))
                saveobjchn(fd,otmp->cobj,mode);
            if (release_data(mode)) {
-               if(otmp->oclass == FOOD_CLASS) food_disappears(otmp);
+               if (otmp->oclass == FOOD_CLASS) food_disappears(otmp);
+               if (otmp->oclass == SPBOOK_CLASS) book_disappears(otmp);
                otmp->where = OBJ_FREE; /* set to free so dealloc will work */
                otmp->timed = 0;        /* not timed any more */
                otmp->lamplit = 0;      /* caller handled lights */
index ff64a11fb3b704f999a75aa477a589d3b6043d8a..3451e19421a3fee61e2c9c4b1296e41b17b2a88f 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)shk.c      3.3     2001/12/06      */
+/*     SCCS Id: @(#)shk.c      3.3     2002/01/19      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -770,9 +770,9 @@ register struct obj *obj, *merge;
        register struct bill_x *bpm;
        register struct monst *shkp;
 
-
        if (obj->otyp == LEASH && obj->leashmon) o_unleash(obj);
        if (obj->oclass == FOOD_CLASS) food_disappears(obj);
+       if (obj->oclass == SPBOOK_CLASS) book_disappears(obj);
        if (Has_contents(obj)) delete_contents(obj);
 
        shkp = 0;
index eecd15b4830b4c849d6b9b2b04f3013986f208a4..0d3fec3b8613163df9512e0ff818af90e2edbbb6 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)spell.c    3.3     2001/12/03      */
+/*     SCCS Id: @(#)spell.c    3.3     2002/01/19      */
 /*     Copyright (c) M. Stephenson 1988                          */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -453,6 +453,15 @@ register struct obj *spellbook;
        return(1);
 }
 
+/* a spellbook has been destroyed or the character has changed levels;
+   the stored address for the current book is no longer valid */
+void
+book_disappears(obj)
+struct obj *obj;
+{
+       if (obj == book) book = (struct obj *)0;
+}
+
 /* renaming an object usually results in it having a different address;
    so the sequence start reading, get interrupted, name the book, resume
    reading would read the "new" book from scratch */
@@ -1176,5 +1185,4 @@ struct obj *obj;
        return;
 }
 
-
 /*spell.c*/