patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Problem: Vim9: divide by zero does not abort expression execution.
Solution: Use a "failed" flag. (issue #7704)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 36fd253..e972033 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4291,9 +4291,10 @@
&& ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER
&& ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER)
{
- typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
- typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
- varnumber_T res = 0;
+ typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
+ typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
+ varnumber_T res = 0;
+ int failed = FALSE;
// both are numbers: compute the result
switch (*op)
@@ -4301,12 +4302,14 @@
case '*': res = tv1->vval.v_number * tv2->vval.v_number;
break;
case '/': res = num_divide(tv1->vval.v_number,
- tv2->vval.v_number);
+ tv2->vval.v_number, &failed);
break;
case '%': res = num_modulus(tv1->vval.v_number,
- tv2->vval.v_number);
+ tv2->vval.v_number, &failed);
break;
}
+ if (failed)
+ return FAIL;
tv1->vval.v_number = res;
--ppconst->pp_used;
}