If divident negative, then remainder is negative too.
[open-adventure.git] / saveresume.c
index f1d52d458423cedd5e01e7bff1dcfc4c45288eff..8bd4418f9e51ac8e2ca0f2ef41b4b4b7cf4e5f00 100644 (file)
@@ -145,6 +145,11 @@ bool is_valid(struct game_t* valgame)
         valgame->lcg_x %= LCG_M;
     }
 
+    /* Check for RNG underflow. Transpose */
+    if (valgame->lcg_x < LCG_M) {
+        valgame->lcg_x = LCG_M + (valgame->lcg_x % LCG_M);
+    }
+
     /*  Bounds check for locations */
     if ( valgame->chloc  < -1 || valgame->chloc  > NLOCATIONS ||
          valgame->chloc2 < -1 || valgame->chloc2 > NLOCATIONS ||