From 22e8f63bacac00f31e944ee5c2578f805b2bf1ac Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 4 May 2022 23:15:12 +0200 Subject: [PATCH] Fixed zero division and zero assertion errors when [] / 0 --- ablescript/src/variables.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 3627a22..0a5fbb6 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -760,8 +760,15 @@ impl ops::Div for Value { } }), Value::Cart(c) => { - let cart_len = c.len(); - let chunk_len = rhs.into_isize() as usize; + let cart_len = match c.len() { + 0 => return Value::Cart(HashMap::new()), + l => l, + }; + + let chunk_len = match rhs.into_isize() as usize { + 0 => rand::thread_rng().gen_range(1..=cart_len), + l => l, + }; Value::Cart( c.into_iter()