diff --git a/src/force.cpp b/src/force.cpp index 0073366c27..e56e250ffc 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -61,20 +61,12 @@ Force::Force(LAMMPS *lmp) : Pointers(lmp) improper = nullptr; kspace = nullptr; - char *str = (char *) "none"; - int n = strlen(str) + 1; - pair_style = new char[n]; - strcpy(pair_style,str); - bond_style = new char[n]; - strcpy(bond_style,str); - angle_style = new char[n]; - strcpy(angle_style,str); - dihedral_style = new char[n]; - strcpy(dihedral_style,str); - improper_style = new char[n]; - strcpy(improper_style,str); - kspace_style = new char[n]; - strcpy(kspace_style,str); + pair_style = utils::strdup("none"); + bond_style = utils::strdup("none"); + angle_style = utils::strdup("none"); + dihedral_style = utils::strdup("none"); + improper_style = utils::strdup("none"); + kspace_style = utils::strdup("none"); pair_restart = nullptr; create_factories(); diff --git a/src/imbalance_store.cpp b/src/imbalance_store.cpp index 9815744b2d..879b434bfd 100644 --- a/src/imbalance_store.cpp +++ b/src/imbalance_store.cpp @@ -36,10 +36,7 @@ ImbalanceStore::~ImbalanceStore() int ImbalanceStore::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); - - int len = strlen(arg[0]) + 1; - name = new char[len]; - memcpy(name,arg[0],len); + name = utils::strdup(arg[0]); return 1; } diff --git a/src/imbalance_var.cpp b/src/imbalance_var.cpp index 2265e6e4c0..d2a4f0d691 100644 --- a/src/imbalance_var.cpp +++ b/src/imbalance_var.cpp @@ -40,10 +40,7 @@ ImbalanceVar::~ImbalanceVar() int ImbalanceVar::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); - - int len = strlen(arg[0]) + 1; - name = new char[len]; - memcpy(name,arg[0],len); + name = utils::strdup(arg[0]); init(0); return 1; diff --git a/src/input.cpp b/src/input.cpp index eeb211a6d1..9ac140753a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1013,9 +1013,7 @@ void Input::jump() if (narg == 2) { label_active = 1; if (labelstr) delete [] labelstr; - int n = strlen(arg[1]) + 1; - labelstr = new char[n]; - strcpy(labelstr,arg[1]); + labelstr = utils::strdup(arg[1]); } } @@ -1840,17 +1838,12 @@ void Input::suffix() if (strcmp(arg[0],"hybrid") == 0) { if (narg != 3) error->all(FLERR,"Illegal suffix command"); - int n = strlen(arg[1]) + 1; - lmp->suffix = new char[n]; - strcpy(lmp->suffix,arg[1]); + lmp->suffix = utils::strdup(arg[1]); n = strlen(arg[2]) + 1; - lmp->suffix2 = new char[n]; - strcpy(lmp->suffix2,arg[2]); + lmp->suffix2 = utils::strdup(arg[2]); } else { if (narg != 1) error->all(FLERR,"Illegal suffix command"); - int n = strlen(arg[0]) + 1; - lmp->suffix = new char[n]; - strcpy(lmp->suffix,arg[0]); + lmp->suffix = utils::strdup(arg[0]); } } }