squadprob array had 5 elements but only 4 initialized

fixes #335
This commit is contained in:
nhmall
2020-04-21 14:32:14 -04:00
parent 52a15daaf6
commit 23428d0fcc
2 changed files with 8 additions and 8 deletions

View File

@@ -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 traversing fmon list; monster detection gave misleading feedback
(blank map instead of 'strange feeling') if there were no other (blank map instead of 'strange feeling') if there were no other
monsters on level; likewise object detection and guard's minvent 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 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository

View File

@@ -780,15 +780,13 @@ courtmon()
return mkclass(S_KOBOLD, 0); return mkclass(S_KOBOLD, 0);
} }
#define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1)
static const struct { static const struct {
unsigned pm; unsigned pm;
unsigned prob; unsigned prob;
} squadprob[NSTYPES] = { { PM_SOLDIER, 80 }, } squadprob[] = { { PM_SOLDIER, 80 },
{ PM_SERGEANT, 15 }, { PM_SERGEANT, 15 },
{ PM_LIEUTENANT, 4 }, { PM_LIEUTENANT, 4 },
{ PM_CAPTAIN, 1 } }; { PM_CAPTAIN, 1 } };
/* return soldier types. */ /* return soldier types. */
static struct permonst * static struct permonst *
@@ -799,14 +797,14 @@ squadmon()
sel_prob = rnd(80 + level_difficulty()); sel_prob = rnd(80 + level_difficulty());
cpro = 0; cpro = 0;
for (i = 0; i < NSTYPES; i++) { for (i = 0; i < SIZE(squadprob); i++) {
cpro += squadprob[i].prob; cpro += squadprob[i].prob;
if (cpro > sel_prob) { if (cpro > sel_prob) {
mndx = squadprob[i].pm; mndx = squadprob[i].pm;
goto gotone; goto gotone;
} }
} }
mndx = squadprob[rn2(NSTYPES)].pm; mndx = squadprob[rn2(SIZE(squadprob))].pm;
gotone: gotone:
if (!(g.mvitals[mndx].mvflags & G_GONE)) if (!(g.mvitals[mndx].mvflags & G_GONE))
return &mons[mndx]; return &mons[mndx];