From 2a10b3003d045345f8d0e1b3479f5025d4891693 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 16 May 2021 16:48:33 -0700 Subject: [PATCH] kill extremely long running games If move counter ever hits one billion, quit. Leaving it unlimited means that it could eventually wrap to a negative value and break various things. --- doc/fixes37.0 | 3 ++- src/allmain.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 6c3b9fffd..78a2ad62c 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -1,4 +1,4 @@ -NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.534 $ $NHDT-Date: 1621131203 2021/05/16 02:13:23 $ +NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.535 $ $NHDT-Date: 1621208908 2021/05/16 23:48:28 $ General Fixes and Modified Features ----------------------------------- @@ -519,6 +519,7 @@ fighter types who start out knowing all non-magic armor should not know prediscovered weapons adjustmens: only knights and samurai know polearms; rangers know launchers (bows), ammo (arrows), and spears regardless of their race/species; likewise, rogues know all daggers +if the move counter ever reaches 1000000000, end the game Fixes to 3.7.0-x Problems that Were Exposed Via git Repository diff --git a/src/allmain.c b/src/allmain.c index ba0a1f0e3..43f436faf 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 allmain.c $NHDT-Date: 1613292825 2021/02/14 08:53:45 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.151 $ */ +/* NetHack 3.7 allmain.c $NHDT-Date: 1621208846 2021/05/16 23:47:26 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.152 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -180,6 +180,19 @@ moveloop(boolean resuming) g.monstermoves++; /* [obsolete (for a long time...)] */ g.moves++; + /* + * Never allow 'moves' to grow big enough to wrap. + * We don't care what the maximum possible 'long int' + * is for the current configuration, we want a value + * that is the same for all viable configurations. + * When imposing the limit, use a mystic decimal value + * instead of a magic binary one such as 0x7fffffffL. + */ + if (g.moves >= 1000000000L) { + display_nhwindow(WIN_MESSAGE, TRUE); + pline_The("dungeon capitulates."); + done(ESCAPED); + } if (flags.time && !g.context.run) iflags.time_botl = TRUE; /* 'moves' just changed */