]> granicus.if.org Git - nethack/commitdiff
mextra follow up bit 2
authornethack.allison <nethack.allison>
Fri, 6 Jan 2006 22:16:46 +0000 (22:16 +0000)
committernethack.allison <nethack.allison>
Fri, 6 Jan 2006 22:16:46 +0000 (22:16 +0000)
<Someone> noticed the leftover zeromextra, this removes it.

Using memset() on a possibly failed mextra allocation was inapprorpriate,
so replace the newmextra() macro with a function.

Prevent a crash in christen_monst() if mextra was not initialized.

include/extern.h
include/mextra.h
src/do_name.c
src/makemon.c

index 485ef24185ecc7205f762305785d23552cde87db..1963e98c40cb7dd436ce1c778002945a4166b659 100644 (file)
@@ -969,6 +969,7 @@ E boolean FDECL(is_home_elemental, (struct permonst *));
 E struct monst *FDECL(clone_mon, (struct monst *,XCHAR_P,XCHAR_P));
 E int FDECL(monhp_per_lvl, (struct monst *));
 E void FDECL(newmonhp, (struct monst *,int));
+E struct mextra *NDECL(newmextra);
 E struct monst *FDECL(makemon, (struct permonst *,int,int,int));
 E boolean FDECL(create_critters, (int,struct permonst *));
 E struct permonst *NDECL(rndmonst);
index e065e0ca477d4df14d10c866fa4a94336a42f312..93478efd17adfd377e424deca335cc7844098764 100644 (file)
@@ -110,10 +110,6 @@ struct mextra {
        struct edog *edog;
 };
 
-#define newmextra()            \
-       (struct mextra *) memset((genericptr_t)alloc(sizeof(struct mextra)), \
-       0, sizeof(struct mextra))
-
 #define MNAME(mon)     ((mon)->mextra->mname)
 #define EGD(mon)       ((mon)->mextra->egd)
 #define EPRI(mon)      ((mon)->mextra->epri)
index b9b11e064c80412c0c399d342680cdef816c600a..fc98f7a5c20aabff1421c78e017f78c495dea4d1 100644 (file)
@@ -233,6 +233,7 @@ const char *name;
                return mtmp;
        }
        if (has_name(mtmp)) free((genericptr_t)MNAME(mtmp));
+       if (!mtmp->mextra) mtmp->mextra = newmextra();
 
        MNAME(mtmp) = (char *)alloc(lth);
        if (lth) Strcpy(MNAME(mtmp), name);
index 51574c2c14189e2518524be82ff8ecf433cb863d..ce988d409959e2d64ff3325e2e1c44950e0216a4 100644 (file)
@@ -9,7 +9,6 @@
 #endif
 
 STATIC_VAR NEARDATA struct monst zeromonst;
-STATIC_VAR NEARDATA struct mextra zeromextra;
 
 /* this assumes that a human quest leader or nemesis is an archetype
    of the corresponding role; that isn't so for some roles (tourist
@@ -853,6 +852,16 @@ int mndx;
     }
 }
 
+struct mextra *
+newmextra()
+{
+       struct mextra *mextra;
+       mextra = (struct mextra *)alloc(sizeof(struct mextra));
+       if (mextra)
+           (void) memset((genericptr_t)mextra, 0, sizeof(struct mextra));
+       return mextra;
+}
+
 /*
  * called with [x,y] = coordinates;
  *     [0,0] means anyplace