simplify some more code by using utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-03-17 00:10:01 -04:00
parent a76a8eae59
commit 2dc0b70575
4 changed files with 12 additions and 33 deletions

View File

@ -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();

View File

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

View File

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

View File

@ -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]);
}
}
}