From: Pasi Kallinen Date: Fri, 3 Apr 2015 11:46:28 +0000 (+0300) Subject: Prevent segfaults, makemon can return null X-Git-Tag: NetHack-3.6.0_RC01~492^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fdc7e980ea2d32d8caea93e2cbc4381d849b6fd7;p=nethack Prevent segfaults, makemon can return null --- diff --git a/src/makemon.c b/src/makemon.c index 799438c2e..cb466220e 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -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. + */ + } } } } diff --git a/src/mhitu.c b/src/mhitu.c index 9ec602895..8450ad12e 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -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);