avm1: Fix Random action

This commit is contained in:
Mike Welsh 2019-09-27 19:32:22 -07:00
parent c8cec3132f
commit e0811be40d
1 changed files with 3 additions and 1 deletions

View File

@ -1056,7 +1056,9 @@ impl<'gc> Avm1<'gc> {
}
fn action_random_number(&mut self, context: &mut ActionContext) -> Result<(), Error> {
let max = self.pop()?.as_f64()? as u32;
// A max value < 0 will always return 0,
// and the max value gets converted into an i32, so any number > 2^31 - 1 will return 0.
let max = self.pop()?.into_number_v1() as i32;
let val = context.rng.gen_range(0, max);
self.push(Value::Number(val.into()));
Ok(())