diff --git a/src/balance.cpp b/src/balance.cpp index 1df2116b72..6b01ce4dae 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -489,32 +489,21 @@ void Balance::options(int iarg, int narg, char **arg) void Balance::weight_storage(char *prefix) { - char *fixargs[6]; + std::string cmd = ""; - if (prefix) { - int n = strlen(prefix) + 32; - fixargs[0] = new char[n]; - strcpy(fixargs[0],prefix); - strcat(fixargs[0],"IMBALANCE_WEIGHTS"); - } else fixargs[0] = (char *) "IMBALANCE_WEIGHTS"; + if (prefix) cmd = prefix; + cmd += "IMBALANCE_WEIGHTS"; - fixargs[1] = (char *) "all"; - fixargs[2] = (char *) "STORE"; - fixargs[3] = (char *) "peratom"; - fixargs[4] = (char *) "0"; - fixargs[5] = (char *) "1"; - - int ifix = modify->find_fix(fixargs[0]); + int ifix = modify->find_fix(cmd.c_str()); if (ifix < 1) { - modify->add_fix(6,fixargs); + cmd += " all STORE peratom 0 1"; + modify->add_fix(cmd); fixstore = (FixStore *) modify->fix[modify->nfix-1]; } else fixstore = (FixStore *) modify->fix[ifix]; // do not carry weights with atoms during normal atom migration fixstore->disable = 1; - - if (prefix) delete [] fixargs[0]; } /* ---------------------------------------------------------------------- diff --git a/src/variable.cpp b/src/variable.cpp index 7c9f7fc057..35eb0781b2 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -5073,24 +5073,16 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) : if (style == ATOMFILE) { if (atom->map_style == 0) - error->all(FLERR, - "Cannot use atomfile-style variable unless atom map exists"); + error->all(FLERR,"Cannot use atomfile-style " + "variable unless an atom map exists"); - int n = strlen(name) + strlen("_VARIABLE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,name); - strcat(id_fix,"_VARIABLE_STORE"); + std::string cmd = name + std::string("_VARIABLE_STORE"); + id_fix = new char[cmd.size()+1]; + strcpy(id_fix,cmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "0"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + cmd += " all STORE peratom 0 1"; + modify->add_fix(cmd); fixstore = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; buffer = new char[CHUNK*MAXLINE]; }