diff --git a/doc/src/Errors_messages.txt b/doc/src/Errors_messages.txt index 4f3bbe8c24..b930dbce30 100644 --- a/doc/src/Errors_messages.txt +++ b/doc/src/Errors_messages.txt @@ -5828,6 +5828,12 @@ Must have periodic x,y dimensions and non-periodic z dimension to use Must have periodic x,y dimensions and non-periodic z dimension to use 2d slab option with pppm/disp. :dd +{Incorrect conversion in format string} :dt + +A format style variable was not using either a %f or a %g conversion. +Or an immediate variable with format suffix was not using either +a %f or a %g conversion in the format suffix. :dd + {Incorrect element names in ADP potential file} :dt The element names in the ADP file do not match those requested. :dd diff --git a/src/input.cpp b/src/input.cpp index f88c8ca0c0..029c155ee8 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -50,6 +50,7 @@ #include "accelerator_kokkos.h" #include "error.h" #include "memory.h" +#include "utils.h" #ifdef _OPENMP #include @@ -526,6 +527,11 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) *fmtflag='\0'; } + // quick check for proper format string + + if (!utils::strmatch(fmtstr,"%[0-9 ]*\\.[0-9]+[fg]")) + error->all(FLERR,"Incorrect conversion in format string"); + snprintf(immediate,256,fmtstr,variable->compute_equal(var)); value = immediate; diff --git a/src/input.h b/src/input.h index 47ad7779f1..d62ab11234 100644 --- a/src/input.h +++ b/src/input.h @@ -173,6 +173,11 @@ E: Unbalanced quotes in input line No matching end double quote was found following a leading double quote. +E: Incorrect conversion in format string + +An immediate variable with format suffix was not using +either a %f or a %g conversion in the format suffix. + E: Input line quote not followed by white-space An end quote must be followed by white-space. diff --git a/src/variable.cpp b/src/variable.cpp index 56b66cad0d..0fe18700ee 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -38,6 +38,7 @@ #include "memory.h" #include "info.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -383,6 +384,8 @@ void Variable::set(int narg, char **arg) num[nvar] = 3; which[nvar] = 0; pad[nvar] = 0; + if (!utils::strmatch(arg[2],"%[0-9 ]*\\.[0-9]+[fg]")) + error->all(FLERR,"Incorrect conversion in format string"); data[nvar] = new char*[num[nvar]]; copy(2,&arg[2],data[nvar]); data[nvar][2] = new char[VALUELENGTH]; diff --git a/src/variable.h b/src/variable.h index a37ee4cff7..a071fdb021 100644 --- a/src/variable.h +++ b/src/variable.h @@ -210,6 +210,10 @@ E: Invalid variable style with next command Variable styles {equal} and {world} cannot be used in a next command. +E: Incorrect conversion in format string + +A format style variable was not using either a %f or a %g conversion. + E: Next command must list all universe and uloop variables This is to insure they stay in sync.