From f0220c4203d5b3ec7a300624d967534bb193df43 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 11 Oct 2015 20:36:28 +0300 Subject: [PATCH] Add monster data sanity checking --- include/extern.h | 1 + src/cmd.c | 1 + src/mon.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/extern.h b/include/extern.h index 059e4fcde..7cae62d8c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1280,6 +1280,7 @@ E int FDECL(cmap_to_type, (int)); /* ### mon.c ### */ +E void NDECL(mon_sanity_check); E int FDECL(undead_to_corpse, (int)); E int FDECL(genus, (int, int)); E int FDECL(pm_to_cham, (int)); diff --git a/src/cmd.c b/src/cmd.c index 7e69ee7c5..63dc9b920 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -3067,6 +3067,7 @@ sanity_check() { obj_sanity_check(); timer_sanity_check(); + mon_sanity_check(); } #ifdef DEBUG_MIGRATING_MONS diff --git a/src/mon.c b/src/mon.c index 44f4c48ae..4e5be3f96 100644 --- a/src/mon.c +++ b/src/mon.c @@ -39,6 +39,40 @@ const char *warnings[] = { }; #endif /* 0 */ + +void +sanity_check_single_mon(mtmp, msg) +struct monst *mtmp; +const char *msg; +{ + if (DEADMONSTER(mtmp)) return; + if ((mtmp->data < &mons[LOW_PM]) || (mtmp->data >= &mons[NUMMONS])) + impossible("illegal mon data (%s)", msg); +} + +void +mon_sanity_check() +{ + int x,y; + struct monst *mtmp = fmon; + + while (mtmp) { + sanity_check_single_mon(mtmp, "fmon"); + mtmp = mtmp->nmon; + } + for (x = 0; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + if ((mtmp = m_at(x,y)) != 0) + sanity_check_single_mon(mtmp, "m_at"); + + mtmp = migrating_mons; + while (mtmp) { + sanity_check_single_mon(mtmp, "migr"); + mtmp = mtmp->nmon; + } +} + + /* convert the monster index of an undead to its living counterpart */ int undead_to_corpse(mndx)