simplify using utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-03-16 09:39:45 -04:00
parent 1ef1a7d865
commit eb90fcecb1
3 changed files with 5 additions and 15 deletions

View File

@ -995,18 +995,14 @@ void Modify::replace_fix(const char *replaceID,
if (jfix >= 0) error->all(FLERR,"Replace_fix ID is already in use");
delete [] fix[ifix]->id;
int n = strlen(arg[0]) + 1;
fix[ifix]->id = new char[n];
strcpy(fix[ifix]->id,arg[0]);
fix[ifix]->id = utils::strdup(arg[0]);
int jgroup = group->find(arg[1]);
if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID");
fix[ifix]->igroup = jgroup;
delete [] fix[ifix]->style;
n = strlen(arg[2]) + 1;
fix[ifix]->style = new char[n];
strcpy(fix[ifix]->style,arg[2]);
fix[ifix]->style = utils::strdup(arg[2]);
// invoke add_fix
// it will find and overwrite the replaceID fix

View File

@ -766,12 +766,8 @@ void Output::create_restart(int narg, char **arg)
delete [] restart2a;
delete [] restart2b;
restart_toggle = 0;
int n = strlen(arg[1]) + 3;
restart2a = new char[n];
strcpy(restart2a,arg[1]);
n = strlen(arg[2]) + 1;
restart2b = new char[n];
strcpy(restart2b,arg[2]);
restart2a = utils::strdup(arg[1]);
restart2b = utils::strdup(arg[2]);
}
// check for multiproc output and an MPI-IO filename

View File

@ -164,9 +164,7 @@ void PairCoulStreitz::coeff(int narg, char **arg)
if (strcmp(arg[i],elements[j]) == 0) break;
map[i-2] = j;
if (j == nelements) {
n = strlen(arg[i]) + 1;
elements[j] = new char[n];
strcpy(elements[j],arg[i]);
elements[j] = utils::strdup(arg[i]);
nelements++;
}
}