Skip to content

Fixed RNG crash bug that affected mod

A modder messaged me on Discord about their mod, Death 'n' Decay, randomly crashing when they executed some debug ACS scripts. They provided me a crash report that pointed to this function:

int DLevelScript::Random (int min, int max)
{
    if (max < min)
    {
        swapvalues (max, min);
    }

    return min + pr_acs(max - min + 1);
}

Where min and max were both equal to -2147483648 (INT_MIN). Somehow, when pr_acs was executed, mod = max - min + 1 equated to 0, which then called this:

// Returns a random number in the range [0,mod)
int operator() (int mod)
{
    return GenRand32() % mod;
}

So, a modulus with mod = 0 caused an integer divide by zero error and crashed Zandronum. Fortunately, this was already fixed in GZDoom than ours and was easy enough to backport. This at least prevented the mod from crashing Zandronum.

Merge request reports

Loading