Enforce the range of random numbers,

...in order to avoid some OoS if a serialized value is out of range on
the target computer.
This commit is contained in:
Guillaume Melquiond 2005-04-30 07:56:44 +00:00
parent d9b0b94b7b
commit ca5a8e4abf

View file

@ -35,7 +35,7 @@ int rng::get_random(int value)
if(random == NULL) {
int res = value;
if(value < 0)
res = rand();
res = rand() & 0x7FFFFFFF;
random_ = &random_->add_child("random");
char buf[100];
@ -44,7 +44,7 @@ int rng::get_random(int value)
return res;
} else {
const int res = atol((*random)["value"].c_str());
const int res = atoi((*random)["value"].c_str());
random_ = random;
return res;
}