Skip to content

Commit

Permalink
Add divide-by-zero check to execute
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jul 6, 2024
1 parent 411956c commit be630e4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/instantiation/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
&WireSource::BinaryOp{op, left, right} => {
let left_val = self.generation_state.get_generation_value(left)?;
let right_val = self.generation_state.get_generation_value(right)?;

match op {
BinaryOperator::Divide | BinaryOperator::Modulo => {
use num::Zero;
if right_val.value.unwrap_integer().is_zero() {
return Err((wire_inst.span, format!("Divide or Modulo by zero: {} / 0", left_val.unwrap_integer())));
}
}
_ => {}
}

compute_binary_op(left_val, op, right_val)
}
WireSource::Constant(value) => TypedValue::from_value(value.clone())
Expand Down

0 comments on commit be630e4

Please sign in to comment.