From: bones_was_here Date: Mon, 5 Feb 2024 20:38:45 +0000 (+1000) Subject: sv_cheats: fix two segfaults when setting it to 0 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ada327fc67c9441b808bcadec87027cd0eee66d9;p=xonotic%2Fdarkplaces.git sv_cheats: fix two segfaults when setting it to 0 Assuming the SVQC program is always running crashes when it's not. Testing if the edict pointer is NULL isn't a valid way to stop at the end of the client slots, which caused this to crash when Xonotic SVQC was running. See 1814b2df58302baa47df6718b09465265dfc7e5c Signed-off-by: bones_was_here --- diff --git a/sv_ccmds.c b/sv_ccmds.c index a210b1cb..af283ddb 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -157,11 +157,11 @@ static void SV_Restart_f(cmd_state_t *cmd) static void SV_DisableCheats_c(cvar_t *var) { prvm_prog_t *prog = SVVM_prog; - int i = 0; + int i; - if (var->value == 0) + if (prog->loaded && var->value == 0) { - while (svs.clients[i].edict) + for (i = 0; i < svs.maxclients; ++i) { if (((int)PRVM_serveredictfloat(svs.clients[i].edict, flags) & FL_GODMODE)) PRVM_serveredictfloat(svs.clients[i].edict, flags) = (int)PRVM_serveredictfloat(svs.clients[i].edict, flags) ^ FL_GODMODE; @@ -173,7 +173,6 @@ static void SV_DisableCheats_c(cvar_t *var) noclip_anglehack = false; PRVM_serveredictfloat(svs.clients[i].edict, movetype) = MOVETYPE_WALK; } - i++; } } }