]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
sv_cheats: fix two segfaults when setting it to 0
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 5 Feb 2024 20:38:45 +0000 (06:38 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 6 Feb 2024 08:04:41 +0000 (18:04 +1000)
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 <bones_was_here@xonotic.au>
sv_ccmds.c

index a210b1cb2342abd563eb22a2a8241a5f7dc44c70..af283ddbb595ef21fe4b79dfb301f0f8c4b25e3f 100644 (file)
@@ -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++;
                }
        }
 }