From 5d941da4e911f0ef08a79e7476d131a72fe68307 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 26 Jan 2023 07:10:20 -0500 Subject: [PATCH] check if variable value is a valid number before converting it --- src/variable.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 78ce8d8758..4285acfb05 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1907,12 +1907,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) char *var = retrieve(word+2); if (var == nullptr) print_var_error(FLERR,"Invalid variable evaluation in variable formula",ivar); - if (tree) { - auto newtree = new Tree(); - newtree->type = VALUE; - newtree->value = atof(var); - treestack[ntreestack++] = newtree; - } else argstack[nargstack++] = atof(var); + if (utils::is_double(var)) { + if (tree) { + auto newtree = new Tree(); + newtree->type = VALUE; + newtree->value = atof(var); + treestack[ntreestack++] = newtree; + } else argstack[nargstack++] = atof(var); + } else print_var_error(FLERR,"Non-numeric variable value in variable formula",ivar); // v_name = per-atom vector from atom-style variable // evaluate the atom-style variable as newtree