From d1deafab05995bdedeaf877afd7667fb40eeac3a Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 6 Jan 2019 20:59:20 -0800 Subject: [PATCH] stale vptrs for obj->{nexthere,ocontainer,ocarry} 'struct obj' contains a union of mutually exclusive pointers, but removing an obj from a list wasn't clearing whichever one had been in use. If something is removed from a monster's inventory, clear the object's pointer back to that monster; if something is removed from a container, clear the object's pointer back to that container; and whenever something is removed from the floor, clear the pointer to the object which followed it at that floor location. --- src/mkobj.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mkobj.c b/src/mkobj.c index cab7c6344..29444b424 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mkobj.c $NHDT-Date: 1545951660 2018/12/27 23:01:00 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.139 $ */ +/* NetHack 3.6 mkobj.c $NHDT-Date: 1546837153 2019/01/07 04:59:13 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.140 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1941,12 +1941,14 @@ struct obj *obj; case OBJ_CONTAINED: extract_nobj(obj, &obj->ocontainer->cobj); container_weight(obj->ocontainer); + obj->ocontainer = (struct obj *) 0; /* clear stale back-link */ break; case OBJ_INVENT: freeinv(obj); break; case OBJ_MINVENT: extract_nobj(obj, &obj->ocarry->minvent); + obj->ocarry = (struct monst *) 0; /* clear stale back-link */ break; case OBJ_MIGRATING: extract_nobj(obj, &migrating_objs); @@ -1983,7 +1985,7 @@ struct obj *obj, **head_ptr; if (!curr) panic("extract_nobj: object lost"); obj->where = OBJ_FREE; - obj->nobj = NULL; + obj->nobj = (struct obj *) 0; } /* @@ -2010,6 +2012,7 @@ struct obj *obj, **head_ptr; } if (!curr) panic("extract_nexthere: object lost"); + obj->nexthere = (struct obj *) 0; } /* -- 2.40.0