Prevent segfaults, makemon can return null

This commit is contained in:
Pasi Kallinen
2015-04-03 14:46:28 +03:00
parent 30bce1ec6b
commit fdc7e980ea
2 changed files with 10 additions and 7 deletions

View File

@@ -122,13 +122,15 @@ register int x, y, n;
*/ */
if (enexto(&mm, mm.x, mm.y, mtmp->data)) { if (enexto(&mm, mm.x, mm.y, mtmp->data)) {
mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS); mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS);
mon->mpeaceful = FALSE; if (mon) {
mon->mavenge = 0; mon->mpeaceful = FALSE;
set_malign(mon); mon->mavenge = 0;
/* Undo the second peace_minded() check in makemon(); if the set_malign(mon);
* monster turned out to be peaceful the first time we /* Undo the second peace_minded() check in makemon(); if the
* didn't create it at all; we don't want a second check. * monster turned out to be peaceful the first time we
*/ * didn't create it at all; we don't want a second check.
*/
}
} }
} }
} }

View File

@@ -2558,6 +2558,7 @@ cloneu()
if (u.mh <= 1) return(struct monst *)0; if (u.mh <= 1) return(struct monst *)0;
if (mvitals[mndx].mvflags & G_EXTINCT) 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); mon = makemon(youmonst.data, u.ux, u.uy, NO_MINVENT|MM_EDOG);
if (!mon) return NULL;
mon->mcloned = 1; mon->mcloned = 1;
mon = christen_monst(mon, plname); mon = christen_monst(mon, plname);
initedog(mon); initedog(mon);