From 9e942262356ec258b232815ede9942eee754fc43 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Thu, 28 Oct 2021 17:48:37 -0400 Subject: [PATCH] Fix: bad cast making sp_lev chameleon light source Giving new_light_source '(genericptr_t) mtmp' leads to the light source's id.a_monst being set to 'mtmp->nmon' rather than 'mtmp', since that's what is stored in the initial byte of the monst struct. When mtmp->nmon == 0x0 this can cause a segfault in do_light_sources. --- src/sp_lev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sp_lev.c b/src/sp_lev.c index f83dc71d0..7898318f2 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -2016,11 +2016,11 @@ create_monster(monster* m, struct mkroom* croom) /* used to give light, now doesn't, or vice versa, or light's range has changed */ if (emits_light(olddata)) - del_light_source(LS_MONSTER, (genericptr_t) mtmp); + del_light_source(LS_MONSTER, monst_to_any(mtmp)); if (emits_light(mtmp->data)) new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data), - LS_MONSTER, (genericptr_t) mtmp); + LS_MONSTER, monst_to_any(mtmp)); } if (!mtmp->perminvis || pm_invisible(olddata)) mtmp->perminvis = pm_invisible(mdat);