From 9700e91d1a2efe4d49ba21fa386fc4ed316d0761 Mon Sep 17 00:00:00 2001 From: WeinaJi Date: Thu, 9 Nov 2023 14:02:31 +0100 Subject: [PATCH] Raise error when dividing vector by zero (#2605) --- src/ivoc/ivocvect.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ivoc/ivocvect.cpp b/src/ivoc/ivocvect.cpp index 31b71e5944..e662334649 100644 --- a/src/ivoc/ivocvect.cpp +++ b/src/ivoc/ivocvect.cpp @@ -2369,7 +2369,11 @@ static Object** v_mul(void* v1) { static Object** v_div(void* v1) { Vect* x = (Vect*) v1; if (hoc_argtype(1) == NUMBER) { - std::for_each(x->begin(), x->end(), [](double& d) { d /= *getarg(1); }); + if (*getarg(1) == 0.0) { + hoc_execerror("Vector", "Division by zero"); + } else { + std::for_each(x->begin(), x->end(), [](double& d) { d /= *getarg(1); }); + } } if (hoc_is_object_arg(1)) { Vect* y = vector_arg(1);