make use of utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-02-04 17:00:44 -05:00
parent ab697be9e7
commit 24bf1e5b0c
23 changed files with 277 additions and 517 deletions

View File

@ -55,25 +55,19 @@ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) :
xstr = ystr = zstr = nullptr;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[3][2]);
xstr = utils::strdup(arg[3]+2);
} else {
xvalue = utils::numeric(FLERR,arg[3],false,lmp);
xstyle = CONSTANT;
}
if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[4][2]);
ystr = utils::strdup(arg[4]+2);
} else {
yvalue = utils::numeric(FLERR,arg[4],false,lmp);
ystyle = CONSTANT;
}
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[5][2]);
zstr = utils::strdup(arg[5]+2);
} else {
zvalue = utils::numeric(FLERR,arg[5],false,lmp);
zstyle = CONSTANT;
@ -96,16 +90,12 @@ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) :
iregion = domain->find_region(arg[iarg+1]);
if (iregion == -1)
error->all(FLERR,"Region ID for fix addforce does not exist");
int n = strlen(arg[iarg+1]) + 1;
idregion = new char[n];
strcpy(idregion,arg[iarg+1]);
idregion = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"energy") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix addforce command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
estr = new char[n];
strcpy(estr,&arg[iarg+1][2]);
estr = utils::strdup(arg[iarg+1]+2);
} else error->all(FLERR,"Illegal fix addforce command");
iarg += 2;
} else error->all(FLERR,"Illegal fix addforce command");