Skip to content

Commit ccac196

Browse files
committed
game: avoid mod 0
1 parent ff2580f commit ccac196

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/game/g_script_actions.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,11 +2420,21 @@ qboolean G_ScriptAction_Accum(gentity_t *ent, char *params)
24202420
}
24212421
else if (!Q_stricmp(lastToken, "random"))
24222422
{
2423+
int randomValue;
2424+
24232425
if (!token[0])
24242426
{
24252427
G_Error("G_ScriptAction_Accum: accum %s requires a parameter\n", lastToken);
24262428
}
2427-
ent->scriptAccumBuffer[bufferIndex] = rand() % atoi(token);
2429+
2430+
randomValue = atoi(token);
2431+
2432+
if (randomValue == 0)
2433+
{
2434+
G_Error("G_ScriptAction_Accum: accum %s requires a random parameter <> 0\n", lastToken);
2435+
}
2436+
2437+
ent->scriptAccumBuffer[bufferIndex] = rand() % randomValue;
24282438
}
24292439
else if (!Q_stricmp(lastToken, "trigger_if_equal"))
24302440
{
@@ -2689,11 +2699,21 @@ qboolean G_ScriptAction_GlobalAccum(gentity_t *ent, char *params)
26892699
}
26902700
else if (!Q_stricmp(lastToken, "random"))
26912701
{
2702+
int randomValue;
2703+
26922704
if (!token[0])
26932705
{
26942706
G_Error("G_ScriptAction_GlobalAccum: globalaccum %s requires a parameter\n", lastToken);
26952707
}
2696-
level.globalAccumBuffer[bufferIndex] = rand() % atoi(token);
2708+
2709+
randomValue = atoi(token);
2710+
2711+
if (randomValue == 0)
2712+
{
2713+
G_Error("G_ScriptAction_GlobalAccum: globalaccum %s requires a random parameter <> 0\n", lastToken);
2714+
}
2715+
2716+
level.globalAccumBuffer[bufferIndex] = rand() % randomValue;
26972717
}
26982718
else if (!Q_stricmp(lastToken, "trigger_if_equal"))
26992719
{

0 commit comments

Comments
 (0)