use utils::strdup() for duplicating strings
This commit is contained in:
27
src/atom.cpp
27
src/atom.cpp
@ -341,11 +341,8 @@ void Atom::settings(Atom *old)
|
|||||||
map_style = old->map_style;
|
map_style = old->map_style;
|
||||||
sortfreq = old->sortfreq;
|
sortfreq = old->sortfreq;
|
||||||
userbinsize = old->userbinsize;
|
userbinsize = old->userbinsize;
|
||||||
if (old->firstgroupname) {
|
if (old->firstgroupname)
|
||||||
int n = strlen(old->firstgroupname) + 1;
|
firstgroupname = utils::strdup(old->firstgroupname);
|
||||||
firstgroupname = new char[n];
|
|
||||||
strcpy(firstgroupname,old->firstgroupname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -532,9 +529,7 @@ void Atom::add_peratom(const char *name, void *address,
|
|||||||
memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom");
|
memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom");
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = strlen(name) + 1;
|
peratom[nperatom].name = utils::strdup(name);
|
||||||
peratom[nperatom].name = new char[n];
|
|
||||||
strcpy(peratom[nperatom].name,name);
|
|
||||||
peratom[nperatom].address = address;
|
peratom[nperatom].address = address;
|
||||||
peratom[nperatom].datatype = datatype;
|
peratom[nperatom].datatype = datatype;
|
||||||
peratom[nperatom].cols = cols;
|
peratom[nperatom].cols = cols;
|
||||||
@ -582,9 +577,7 @@ void Atom::add_peratom_vary(const char *name, void *address,
|
|||||||
memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom");
|
memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom");
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = strlen(name) + 1;
|
peratom[nperatom].name = utils::strdup(name);
|
||||||
peratom[nperatom].name = new char[n];
|
|
||||||
strcpy(peratom[nperatom].name,name);
|
|
||||||
peratom[nperatom].address = address;
|
peratom[nperatom].address = address;
|
||||||
peratom[nperatom].datatype = datatype;
|
peratom[nperatom].datatype = datatype;
|
||||||
peratom[nperatom].cols = -1;
|
peratom[nperatom].cols = -1;
|
||||||
@ -815,9 +808,7 @@ void Atom::modify_params(int narg, char **arg)
|
|||||||
delete [] firstgroupname;
|
delete [] firstgroupname;
|
||||||
firstgroupname = nullptr;
|
firstgroupname = nullptr;
|
||||||
} else {
|
} else {
|
||||||
int n = strlen(arg[iarg+1]) + 1;
|
firstgroupname = utils::strdup(arg[iarg+1]);
|
||||||
firstgroupname = new char[n];
|
|
||||||
strcpy(firstgroupname,arg[iarg+1]);
|
|
||||||
sortfreq = 0;
|
sortfreq = 0;
|
||||||
}
|
}
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
@ -2427,9 +2418,7 @@ int Atom::add_custom(const char *name, int flag)
|
|||||||
nivector++;
|
nivector++;
|
||||||
iname = (char **) memory->srealloc(iname,nivector*sizeof(char *),
|
iname = (char **) memory->srealloc(iname,nivector*sizeof(char *),
|
||||||
"atom:iname");
|
"atom:iname");
|
||||||
int n = strlen(name) + 1;
|
iname[index] = utils::strdup(name);
|
||||||
iname[index] = new char[n];
|
|
||||||
strcpy(iname[index],name);
|
|
||||||
ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *),
|
ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *),
|
||||||
"atom:ivector");
|
"atom:ivector");
|
||||||
memory->create(ivector[index],nmax,"atom:ivector");
|
memory->create(ivector[index],nmax,"atom:ivector");
|
||||||
@ -2438,9 +2427,7 @@ int Atom::add_custom(const char *name, int flag)
|
|||||||
ndvector++;
|
ndvector++;
|
||||||
dname = (char **) memory->srealloc(dname,ndvector*sizeof(char *),
|
dname = (char **) memory->srealloc(dname,ndvector*sizeof(char *),
|
||||||
"atom:dname");
|
"atom:dname");
|
||||||
int n = strlen(name) + 1;
|
dname[index] = utils::strdup(name);
|
||||||
dname[index] = new char[n];
|
|
||||||
strcpy(dname[index],name);
|
|
||||||
dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *),
|
dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *),
|
||||||
"atom:dvector");
|
"atom:dvector");
|
||||||
memory->create(dvector[index],nmax,"atom:dvector");
|
memory->create(dvector[index],nmax,"atom:dvector");
|
||||||
|
|||||||
@ -154,11 +154,8 @@ void AtomVec::store_args(int narg, char **arg)
|
|||||||
nargcopy = narg;
|
nargcopy = narg;
|
||||||
if (nargcopy) argcopy = new char*[nargcopy];
|
if (nargcopy) argcopy = new char*[nargcopy];
|
||||||
else argcopy = nullptr;
|
else argcopy = nullptr;
|
||||||
for (int i = 0; i < nargcopy; i++) {
|
for (int i = 0; i < nargcopy; i++)
|
||||||
int n = strlen(arg[i]) + 1;
|
argcopy[i] = utils::strdup(arg[i]);
|
||||||
argcopy[i] = new char[n];
|
|
||||||
strcpy(argcopy[i],arg[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|||||||
@ -109,8 +109,7 @@ void AtomVecHybrid::process_args(int narg, char **arg)
|
|||||||
if (strcmp(arg[iarg],keywords[i]) == 0)
|
if (strcmp(arg[iarg],keywords[i]) == 0)
|
||||||
error->all(FLERR,"Atom style hybrid cannot use same atom style twice");
|
error->all(FLERR,"Atom style hybrid cannot use same atom style twice");
|
||||||
styles[nstyles] = atom->new_avec(arg[iarg],1,dummy);
|
styles[nstyles] = atom->new_avec(arg[iarg],1,dummy);
|
||||||
keywords[nstyles] = new char[strlen(arg[iarg])+1];
|
keywords[nstyles] = utils::strdup(arg[iarg]);
|
||||||
strcpy(keywords[nstyles],arg[iarg]);
|
|
||||||
jarg = iarg + 1;
|
jarg = iarg + 1;
|
||||||
while (jarg < narg && !known_style(arg[jarg])) jarg++;
|
while (jarg < narg && !known_style(arg[jarg])) jarg++;
|
||||||
styles[nstyles]->process_args(jarg-iarg-1,&arg[iarg+1]);
|
styles[nstyles]->process_args(jarg-iarg-1,&arg[iarg+1]);
|
||||||
@ -601,13 +600,10 @@ void AtomVecHybrid::build_styles()
|
|||||||
|
|
||||||
allstyles = new char*[nallstyles];
|
allstyles = new char*[nallstyles];
|
||||||
|
|
||||||
int n;
|
|
||||||
nallstyles = 0;
|
nallstyles = 0;
|
||||||
#define ATOM_CLASS
|
#define ATOM_CLASS
|
||||||
#define AtomStyle(key,Class) \
|
#define AtomStyle(key,Class) \
|
||||||
n = strlen(#key) + 1; \
|
allstyles[nallstyles] = utils::strdup(#key); \
|
||||||
allstyles[nallstyles] = new char[n]; \
|
|
||||||
strcpy(allstyles[nallstyles],#key); \
|
|
||||||
nallstyles++;
|
nallstyles++;
|
||||||
#include "style_atom.h" // IWYU pragma: keep
|
#include "style_atom.h" // IWYU pragma: keep
|
||||||
#undef AtomStyle
|
#undef AtomStyle
|
||||||
|
|||||||
@ -20,9 +20,7 @@ using namespace LAMMPS_NS;
|
|||||||
|
|
||||||
Body::Body(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
Body::Body(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
||||||
{
|
{
|
||||||
int n = strlen(arg[0]) + 1;
|
style = utils::strdup(arg[0]);
|
||||||
style = new char[n];
|
|
||||||
strcpy(style,arg[0]);
|
|
||||||
icp = nullptr;
|
icp = nullptr;
|
||||||
dcp = nullptr;
|
dcp = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/comm.cpp
23
src/comm.cpp
@ -149,16 +149,11 @@ void Comm::copy_arrays(Comm *oldcomm)
|
|||||||
memcpy(cutusermulti,oldcomm->cutusermulti,atom->ntypes+1);
|
memcpy(cutusermulti,oldcomm->cutusermulti,atom->ntypes+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customfile) {
|
if (customfile)
|
||||||
int n = strlen(oldcomm->customfile) + 1;
|
customfile = utils::strdup(oldcomm->customfile);
|
||||||
customfile = new char[n];
|
|
||||||
strcpy(customfile,oldcomm->customfile);
|
if (outfile)
|
||||||
}
|
outfile = utils::strdup(oldcomm->outfile);
|
||||||
if (outfile) {
|
|
||||||
int n = strlen(oldcomm->outfile) + 1;
|
|
||||||
outfile = new char[n];
|
|
||||||
strcpy(outfile,oldcomm->outfile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -391,9 +386,7 @@ void Comm::set_processors(int narg, char **arg)
|
|||||||
if (iarg+3 > narg) error->all(FLERR,"Illegal processors command");
|
if (iarg+3 > narg) error->all(FLERR,"Illegal processors command");
|
||||||
gridflag = CUSTOM;
|
gridflag = CUSTOM;
|
||||||
delete [] customfile;
|
delete [] customfile;
|
||||||
int n = strlen(arg[iarg+2]) + 1;
|
customfile = utils::strdup(arg[iarg+2]);
|
||||||
customfile = new char[n];
|
|
||||||
strcpy(customfile,arg[iarg+2]);
|
|
||||||
iarg += 1;
|
iarg += 1;
|
||||||
|
|
||||||
} else error->all(FLERR,"Illegal processors command");
|
} else error->all(FLERR,"Illegal processors command");
|
||||||
@ -453,9 +446,7 @@ void Comm::set_processors(int narg, char **arg)
|
|||||||
} else if (strcmp(arg[iarg],"file") == 0) {
|
} else if (strcmp(arg[iarg],"file") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal processors command");
|
if (iarg+2 > narg) error->all(FLERR,"Illegal processors command");
|
||||||
delete [] outfile;
|
delete [] outfile;
|
||||||
int n = strlen(arg[iarg+1]) + 1;
|
outfile = utils::strdup(arg[iarg+1]);
|
||||||
outfile = new char[n];
|
|
||||||
strcpy(outfile,arg[iarg+1]);
|
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
|
|
||||||
} else error->all(FLERR,"Illegal processors command");
|
} else error->all(FLERR,"Illegal processors command");
|
||||||
|
|||||||
@ -554,9 +554,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg,
|
|||||||
earg = (char **)
|
earg = (char **)
|
||||||
lmp->memory->srealloc(earg,maxarg*sizeof(char *),"input:earg");
|
lmp->memory->srealloc(earg,maxarg*sizeof(char *),"input:earg");
|
||||||
}
|
}
|
||||||
n = strlen(arg[iarg]) + 1;
|
earg[newarg] = utils::strdup(arg[iarg]);
|
||||||
earg[newarg] = new char[n];
|
|
||||||
strcpy(earg[newarg],arg[iarg]);
|
|
||||||
newarg++;
|
newarg++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user