simplify by using utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-03-16 08:35:06 -04:00
parent 2f8770971c
commit 5d5fc4a04d
6 changed files with 19 additions and 57 deletions

View File

@ -64,9 +64,7 @@ ReadDump::ReadDump(LAMMPS *lmp) : Pointers(lmp)
fields = nullptr;
buf = nullptr;
int n = strlen("native") + 1;
readerstyle = new char[n];
strcpy(readerstyle,"native");
readerstyle = utils::strdup("native");
nreader = 0;
readers = nullptr;
@ -182,9 +180,7 @@ void ReadDump::store_files(int nstr, char **str)
// either all or none of files must have '%' wild-card
for (int i = 0; i < nfile; i++) {
int n = strlen(str[i]) + 1;
files[i] = new char[n];
strcpy(files[i],str[i]);
files[i] = utils::strdup(str[i]);
if (i == 0) {
if (strchr(files[i],'%')) multiproc = 1;
@ -1258,9 +1254,7 @@ int ReadDump::fields_and_keywords(int narg, char **arg)
for (i = 0; i < nfield; i++)
if (type == fieldtype[i]) break;
if (i == nfield) error->all(FLERR,"Illegal read_dump command");
int n = strlen(arg[iarg+2]) + 1;
fieldlabel[i] = new char[n];
strcpy(fieldlabel[i],arg[iarg+2]);
fieldlabel[i] = utils::strdup(arg[iarg+2]);
iarg += 3;
} else if (strcmp(arg[iarg],"scaled") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_dump command");
@ -1277,9 +1271,7 @@ int ReadDump::fields_and_keywords(int narg, char **arg)
} else if (strcmp(arg[iarg],"format") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal read_dump command");
delete [] readerstyle;
int n = strlen(arg[iarg+1]) + 1;
readerstyle = new char[n];
strcpy(readerstyle,arg[iarg+1]);
readerstyle = utils::strdup(arg[iarg+1]);
iarg += 2;
break;
} else error->all(FLERR,"Illegal read_dump command");