From: Pasi Kallinen Date: Fri, 16 Jun 2017 15:27:25 +0000 (+0300) Subject: Add sanity checking for long worms X-Git-Tag: NetHack-3.6.1_RC01~471 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60443a4ee749ec8d8d5ebcf24ade35ace39cab38;p=nethack Add sanity checking for long worms --- diff --git a/include/extern.h b/include/extern.h index 72df6d58d..6b92d680d 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2761,6 +2761,7 @@ E void FDECL(detect_wsegs, (struct monst *, BOOLEAN_P)); E void FDECL(save_worm, (int, int)); E void FDECL(rest_worm, (int)); E void FDECL(place_wsegs, (struct monst *)); +E void FDECL(sanity_check_worm, (struct monst *)); E void FDECL(remove_worm, (struct monst *)); E void FDECL(place_worm_tail_randomly, (struct monst *, XCHAR_P, XCHAR_P)); E int FDECL(size_wseg, (struct monst *)); diff --git a/src/mon.c b/src/mon.c index 33a84372e..69d64490b 100644 --- a/src/mon.c +++ b/src/mon.c @@ -93,6 +93,8 @@ mon_sanity_check() else if (level.monsters[x][y] != mtmp) impossible("mon (%s) at <%d,%d> is not there!", fmt_ptr((genericptr_t) mtmp), x, y); + else if (mtmp->wormno) + sanity_check_worm(mtmp); } for (x = 0; x < COLNO; x++) diff --git a/src/worm.c b/src/worm.c index ac69ea72b..4e5d12dd8 100644 --- a/src/worm.c +++ b/src/worm.c @@ -569,6 +569,28 @@ struct monst *worm; } } +void +sanity_check_worm(worm) +struct monst *worm; +{ + struct wseg *curr; + + if (!worm) + panic("no worm!"); + if (!worm->wormno) + panic("not a worm?!"); + + curr = wtails[worm->wormno]; + + while (curr != wheads[worm->wormno]) { + if (!isok(curr->wx, curr->wy)) + panic("worm seg not isok"); + if (level.monsters[curr->wx][curr->wy] != worm) + panic("worm not at seg location"); + curr = curr->nseg; + } +} + /* * remove_worm() *