From 23428d0fccf4e96bf0ea508990adf45631611ecc Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 21 Apr 2020 14:32:14 -0400 Subject: [PATCH] squadprob array had 5 elements but only 4 initialized fixes #335 --- doc/fixes37.0 | 2 ++ src/mkroom.c | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 7bddea145..72cbdaab9 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -155,6 +155,8 @@ monster or object detection found semi-dead vault guard at <0,0> while traversing fmon list; monster detection gave misleading feedback (blank map instead of 'strange feeling') if there were no other monsters on level; likewise object detection and guard's minvent +squadprob[] in mkroom.c was defined with 5 elements but initialized only 4 + resulting in giant ants sometimes Fixes to 3.7.0-x Problems that Were Exposed Via git Repository diff --git a/src/mkroom.c b/src/mkroom.c index ffb076658..d41b74b39 100644 --- a/src/mkroom.c +++ b/src/mkroom.c @@ -780,15 +780,13 @@ courtmon() return mkclass(S_KOBOLD, 0); } -#define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1) - static const struct { unsigned pm; unsigned prob; -} squadprob[NSTYPES] = { { PM_SOLDIER, 80 }, - { PM_SERGEANT, 15 }, - { PM_LIEUTENANT, 4 }, - { PM_CAPTAIN, 1 } }; +} squadprob[] = { { PM_SOLDIER, 80 }, + { PM_SERGEANT, 15 }, + { PM_LIEUTENANT, 4 }, + { PM_CAPTAIN, 1 } }; /* return soldier types. */ static struct permonst * @@ -799,14 +797,14 @@ squadmon() sel_prob = rnd(80 + level_difficulty()); cpro = 0; - for (i = 0; i < NSTYPES; i++) { + for (i = 0; i < SIZE(squadprob); i++) { cpro += squadprob[i].prob; if (cpro > sel_prob) { mndx = squadprob[i].pm; goto gotone; } } - mndx = squadprob[rn2(NSTYPES)].pm; + mndx = squadprob[rn2(SIZE(squadprob))].pm; gotone: if (!(g.mvitals[mndx].mvflags & G_GONE)) return &mons[mndx];