diff src/vim9execute.c @ 23673:6d35bc0f161e v8.2.2378

patch 8.2.2378: Vim9: no error message for dividing by zero Commit: https://github.com/vim/vim/commit/99880f96cf444014d589fc1d99bb164deaba71ce Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 20 21:23:14 2021 +0100 patch 8.2.2378: Vim9: no error message for dividing by zero Problem: Vim9: no error message for dividing by zero. Solution: Give an error message. (issue https://github.com/vim/vim/issues/7704)
author Bram Moolenaar <Bram@vim.org>
date Wed, 20 Jan 2021 21:30:04 +0100
parents 9ee9c4246a7f
children 423af0f7beae
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2954,10 +2954,16 @@ call_def_function(
 			switch (iptr->isn_arg.op.op_type)
 			{
 			    case EXPR_MULT: n1 = n1 * n2; break;
-			    case EXPR_DIV:  n1 = num_divide(n1, n2); break;
+			    case EXPR_DIV:  n1 = num_divide(n1, n2);
+					    if (n2 == 0)
+						goto on_error;
+					    break;
 			    case EXPR_SUB:  n1 = n1 - n2; break;
 			    case EXPR_ADD:  n1 = n1 + n2; break;
-			    default:	    n1 = num_modulus(n1, n2); break;
+			    default:	    n1 = num_modulus(n1, n2);
+					    if (n2 == 0)
+						goto on_error;
+					    break;
 			}
 			clear_tv(tv1);
 			clear_tv(tv2);