From 62906e732edc4eaacb535b12453366179e08284d Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Fri, 4 Mar 2022 16:54:26 +0200 Subject: [PATCH] Trap sanity checking --- include/extern.h | 1 + src/cmd.c | 1 + src/trap.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/extern.h b/include/extern.h index 9c60cb2d7..f1b638c7e 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2736,6 +2736,7 @@ extern void sokoban_guilt(void); extern const char * trapname(int, boolean); extern void ignite_items(struct obj *); extern void trap_ice_effects(xchar x, xchar y, boolean ice_is_melting); +extern void trap_sanity_check(void); /* ### u_init.c ### */ diff --git a/src/cmd.c b/src/cmd.c index 09c85b5f2..77380d533 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -3419,6 +3419,7 @@ sanity_check(void) mon_sanity_check(); light_sources_sanity_check(); bc_sanity_check(); + trap_sanity_check(); } #ifdef DEBUG_MIGRATING_MONS diff --git a/src/trap.c b/src/trap.c index 3f881a5e1..4aa7125d1 100644 --- a/src/trap.c +++ b/src/trap.c @@ -6125,4 +6125,20 @@ trap_ice_effects(xchar x, xchar y, boolean ice_is_melting) } } } + +/* sanity check traps */ +void +trap_sanity_check(void) +{ + struct trap *ttmp = g.ftrap; + + while (ttmp) { + if (!isok(ttmp->tx, ttmp->ty)) + impossible("trap sanity: location"); + if (ttmp->ttyp < 0 || ttmp->ttyp >= TRAPNUM) + impossible("trap sanity: type"); + ttmp = ttmp->ntrap; + } +} + /*trap.c*/