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.
This commit is contained in:
Michael Meyer
2021-10-28 18:00:27 -04:00
parent d736cbd751
commit 9e94226235
+2 -2
View File
@@ -2016,11 +2016,11 @@ create_monster(monster* m, struct mkroom* croom)
/* used to give light, now doesn't, or vice versa, /* used to give light, now doesn't, or vice versa,
or light's range has changed */ or light's range has changed */
if (emits_light(olddata)) 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)) if (emits_light(mtmp->data))
new_light_source(mtmp->mx, mtmp->my, new_light_source(mtmp->mx, mtmp->my,
emits_light(mtmp->data), emits_light(mtmp->data),
LS_MONSTER, (genericptr_t) mtmp); LS_MONSTER, monst_to_any(mtmp));
} }
if (!mtmp->perminvis || pm_invisible(olddata)) if (!mtmp->perminvis || pm_invisible(olddata))
mtmp->perminvis = pm_invisible(mdat); mtmp->perminvis = pm_invisible(mdat);