]> granicus.if.org Git - nethack/commitdiff
Prevent segfaults, makemon can return null
authorPasi Kallinen <paxed@alt.org>
Fri, 3 Apr 2015 11:46:28 +0000 (14:46 +0300)
committerPasi Kallinen <paxed@alt.org>
Fri, 3 Apr 2015 11:46:28 +0000 (14:46 +0300)
src/makemon.c
src/mhitu.c

index 799438c2e451fe47744c8898159f8b09eccaba5a..cb466220e0ecb1e77baf31ca29f8f64ab8a62e7c 100644 (file)
@@ -122,13 +122,15 @@ register int x, y, n;
                 */
                if (enexto(&mm, mm.x, mm.y, mtmp->data)) {
                    mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS);
-                   mon->mpeaceful = FALSE;
-                   mon->mavenge = 0;
-                   set_malign(mon);
-                   /* Undo the second peace_minded() check in makemon(); if the
-                    * monster turned out to be peaceful the first time we
-                    * didn't create it at all; we don't want a second check.
-                    */
+                   if (mon) {
+                       mon->mpeaceful = FALSE;
+                       mon->mavenge = 0;
+                       set_malign(mon);
+                       /* Undo the second peace_minded() check in makemon(); if the
+                        * monster turned out to be peaceful the first time we
+                        * didn't create it at all; we don't want a second check.
+                        */
+                   }
                }
        }
 }
index 9ec602895af88c9240343893aadae8dc46f29ff5..8450ad12e6672e993a85c877e15a122ab798e9cb 100644 (file)
@@ -2558,6 +2558,7 @@ cloneu()
        if (u.mh <= 1) return(struct monst *)0;
        if (mvitals[mndx].mvflags & G_EXTINCT) return(struct monst *)0;
        mon = makemon(youmonst.data, u.ux, u.uy, NO_MINVENT|MM_EDOG);
+       if (!mon) return NULL;
        mon->mcloned = 1;
        mon = christen_monst(mon, plname);
        initedog(mon);