simplify by using utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-03-18 19:58:04 -04:00
parent c5ab2becd7
commit 59c0325f08
29 changed files with 53 additions and 135 deletions

View File

@ -37,10 +37,10 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
peflag = 1;
timeflag = 1;
int n = strlen(arg[3]) + 1;
if (lmp->suffix) n += strlen(lmp->suffix) + 1;
pstyle = new char[n];
strcpy(pstyle,arg[3]);
// copy with suffix so we can later chop it off, if needed
if (lmp->suffix)
pstyle = utils::strdup(fmt::format("{}/{}",arg[3],lmp->suffix));
else pstyle = utils::strdup(arg[3]);
int iarg = 4;
nsub = 0;
@ -67,8 +67,7 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
pair = force->pair_match(pstyle,1,nsub);
if (!pair && lmp->suffix) {
strcat(pstyle,"/");
strcat(pstyle,lmp->suffix);
pstyle[strlen(pstyle) - strlen(lmp->suffix) - 1] = '\0';
pair = force->pair_match(pstyle,1,nsub);
}