check if variable value is a valid number before converting it

This commit is contained in:
Axel Kohlmeyer
2023-01-26 07:10:20 -05:00
parent f7725242fa
commit 5d941da4e9

View File

@ -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