[Scummvm-git-logs] scummvm master -> de1338787f65ac0b7a225b8149eebe8d27005fc3
antoniou79
a.antoniou79 at gmail.com
Mon Aug 2 10:40:14 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
de1338787f COMMON: Fix divide by zero in getRandomNumber()
Commit: de1338787f65ac0b7a225b8149eebe8d27005fc3
https://github.com/scummvm/scummvm/commit/de1338787f65ac0b7a225b8149eebe8d27005fc3
Author: Aapo Vienamo (aapo.vienamo at iki.fi)
Date: 2021-08-02T13:40:11+03:00
Commit Message:
COMMON: Fix divide by zero in getRandomNumber()
Calling RandomSource::getRandomNumber() results in divide by zero
exception when called with max = 4294967295 as max + 1 overflows to zero
and the subsequent modulus operation causes the exception.
Certain game saves in Bladerunner trigger this.
Changed paths:
common/random.cpp
diff --git a/common/random.cpp b/common/random.cpp
index d39f9a4255..ed3bc4dbb8 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -20,6 +20,8 @@
*
*/
+#include <climits>
+
#include "common/random.h"
#include "common/system.h"
#include "gui/EventRecorder.h"
@@ -46,6 +48,9 @@ void RandomSource::setSeed(uint32 seed) {
uint RandomSource::getRandomNumber(uint max) {
_randSeed = 0xDEADBF03 * (_randSeed + 1);
_randSeed = (_randSeed >> 13) | (_randSeed << 19);
+
+ if (max == UINT_MAX)
+ return _randSeed;
return _randSeed % (max + 1);
}
More information about the Scummvm-git-logs
mailing list