From 28837dd034782f86ef14b9c0b279e69a35ac8800 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sat, 30 Sep 2023 14:17:47 +0200 Subject: [PATCH] port: different fix for chrAlertOthersOfInjury crash --- src/game/chraction.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/game/chraction.c b/src/game/chraction.c index 04ceeb77e..1f1dd0f18 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -8275,7 +8275,12 @@ void chrAlertOthersOfInjury(struct chrdata *chr, bool dying) index = chr->act_dead.notifychrindex; } +#ifdef AVOID_UB + // notifychrindex can be < 0, so avoid reading g_ChrSlots when that is the case + for (; index >= 0 && index < numchrs && numinrange < 7; index++) { +#else for (; index < numchrs && numinrange < 7; index++) { +#endif struct chrdata *loopchr = &g_ChrSlots[index]; if (loopchr->model && loopchr->prop && (loopchr->prop->flags & PROPFLAG_ENABLED)) { @@ -8488,12 +8493,6 @@ void chrTickDruggedComingUp(struct chrdata *chr) chrUncloak(chr, true); chr->actiontype = ACT_DRUGGEDDROP; -#ifdef AVOID_UB - // the function that checks notifychrindex checks for ACT_DRUGGEDDROP, - // so in theory it could check it before the drop animation is finished, - // which will cause a crash. or at least I think that's what's happening - chr->act_die.notifychrindex = 0; -#endif while (!done) { if (i >= 0