]> granicus.if.org Git - nethack/commitdiff
avoid mkclass() infinite loop (trunk only)
authornethack.rankin <nethack.rankin>
Thu, 21 Apr 2011 00:29:26 +0000 (00:29 +0000)
committernethack.rankin <nethack.rankin>
Thu, 21 Apr 2011 00:29:26 +0000 (00:29 +0000)
     Back on Feb 28, I committed a patch to prevent the special level
loader from generating mail daemons for levels which specified random
demons.  It had a pair of copy+paste mistakes that could result in
mkclass() looping forever.  It was looking at the same monster every
time and if that monster was one which mustn't be generated, it would
just keep repeating.

src/makemon.c

index 2b7a2846c89c13d4714db42d9201297cf1ea5909..27db7259bd3641e61c9091a2d82715bbae67c67c 100644 (file)
@@ -1430,7 +1430,7 @@ int       spc;
  *                     order of strength.
  */
        for(num = rnd(num); num > 0; first++)
-           if (mk_gen_ok(last, G_GONE, mask)) {
+           if (mk_gen_ok(first, G_GONE, mask)) {
                /* skew towards lower value monsters at lower exp. levels */
                num -= mons[first].geno & G_FREQ;
                if (num && adj_lev(&mons[first]) > (u.ulevel*2)) {
@@ -1465,7 +1465,7 @@ int class;
        if (!num) return NON_PM;
 
        for (num = rnd(num); num > 0; first++)
-           if (mk_gen_ok(last, G_GENOD, (G_NOGEN|G_UNIQ)))
+           if (mk_gen_ok(first, G_GENOD, (G_NOGEN|G_UNIQ)))
                num -= mons[first].geno & G_FREQ;
        first--; /* correct an off-by-one error */