fix some issues flagged by coverity scan

This commit is contained in:
Axel Kohlmeyer
2025-01-14 22:23:24 -05:00
parent 5f50278241
commit 2cbdaf8a6a
4 changed files with 10 additions and 13 deletions

View File

@ -581,9 +581,8 @@ FixIMD::FixIMD(LAMMPS *lmp, int narg, char **arg) :
msglen += 3*4*num_coords+IMDHEADERSIZE; msglen += 3*4*num_coords+IMDHEADERSIZE;
} }
msgdata = new char[msglen]; msgdata = new char[msglen];
} } else {
else { msglen = 3*(int)sizeof(float)*num_coords+IMDHEADERSIZE;
msglen = 3*sizeof(float)*num_coords+IMDHEADERSIZE;
msgdata = new char[msglen]; msgdata = new char[msglen];
} }

View File

@ -49,7 +49,6 @@ FixAppendAtoms::FixAppendAtoms(LAMMPS *lmp, int narg, char **arg) :
scaleflag = 1; scaleflag = 1;
spatflag=0; spatflag=0;
spatialid = nullptr;
size = 0.0; size = 0.0;
xloflag = xhiflag = yloflag = yhiflag = zloflag = zhiflag = 0; xloflag = xhiflag = yloflag = yhiflag = zloflag = zhiflag = 0;
@ -60,9 +59,6 @@ FixAppendAtoms::FixAppendAtoms(LAMMPS *lmp, int narg, char **arg) :
rany = 0.0; rany = 0.0;
ranz = 0.0; ranz = 0.0;
randomx = nullptr;
randomt = nullptr;
if (domain->lattice->nbasis == 0) if (domain->lattice->nbasis == 0)
error->all(FLERR,"Fix append/atoms requires a lattice be defined"); error->all(FLERR,"Fix append/atoms requires a lattice be defined");
@ -123,6 +119,7 @@ FixAppendAtoms::FixAppendAtoms(LAMMPS *lmp, int narg, char **arg) :
if (strcmp(arg[iarg+1],"f_") == 0) if (strcmp(arg[iarg+1],"f_") == 0)
error->all(FLERR, "Bad fix ID in fix append/atoms command"); error->all(FLERR, "Bad fix ID in fix append/atoms command");
spatflag = 1; spatflag = 1;
delete[] spatialid;
spatialid = utils::strdup(arg[iarg+1]+2); spatialid = utils::strdup(arg[iarg+1]+2);
spatlead = utils::numeric(FLERR,arg[iarg+2],false,lmp); spatlead = utils::numeric(FLERR,arg[iarg+2],false,lmp);
iarg += 3; iarg += 3;
@ -152,6 +149,7 @@ FixAppendAtoms::FixAppendAtoms(LAMMPS *lmp, int narg, char **arg) :
ranz = utils::numeric(FLERR,arg[iarg+3],false,lmp); ranz = utils::numeric(FLERR,arg[iarg+3],false,lmp);
xseed = utils::inumeric(FLERR,arg[iarg+4],false,lmp); xseed = utils::inumeric(FLERR,arg[iarg+4],false,lmp);
if (xseed <= 0) error->all(FLERR,"Illegal fix append/atoms command"); if (xseed <= 0) error->all(FLERR,"Illegal fix append/atoms command");
delete randomx;
randomx = new RanMars(lmp,xseed + comm->me); randomx = new RanMars(lmp,xseed + comm->me);
iarg += 5; iarg += 5;
} else if (strcmp(arg[iarg],"temp") == 0) { } else if (strcmp(arg[iarg],"temp") == 0) {
@ -165,7 +163,10 @@ FixAppendAtoms::FixAppendAtoms(LAMMPS *lmp, int narg, char **arg) :
if (t_period <= 0) error->all(FLERR,"Illegal fix append/atoms command"); if (t_period <= 0) error->all(FLERR,"Illegal fix append/atoms command");
if (t_extent <= 0) error->all(FLERR,"Illegal fix append/atoms command"); if (t_extent <= 0) error->all(FLERR,"Illegal fix append/atoms command");
if (tseed <= 0) error->all(FLERR,"Illegal fix append/atoms command"); if (tseed <= 0) error->all(FLERR,"Illegal fix append/atoms command");
delete randomt;
randomt = new RanMars(lmp,tseed + comm->me); randomt = new RanMars(lmp,tseed + comm->me);
delete[] gfactor1;
delete[] gfactor2;
gfactor1 = new double[atom->ntypes+1]; gfactor1 = new double[atom->ntypes+1];
gfactor2 = new double[atom->ntypes+1]; gfactor2 = new double[atom->ntypes+1];
iarg += 5; iarg += 5;

View File

@ -55,16 +55,10 @@ ComputeVoronoi::ComputeVoronoi(LAMMPS *lmp, int narg, char **arg) :
surface = VOROSURF_NONE; surface = VOROSURF_NONE;
maxedge = 0; maxedge = 0;
fthresh = ethresh = 0.0; fthresh = ethresh = 0.0;
radstr = nullptr;
onlyGroup = false; onlyGroup = false;
occupation = false; occupation = false;
con_mono = nullptr;
con_poly = nullptr;
tags = nullptr;
oldmaxtag = 0; oldmaxtag = 0;
occvec = sendocc = lroot = lnext = nullptr;
faces = nullptr;
int iarg = 3; int iarg = 3;
while (iarg<narg) { while (iarg<narg) {
@ -79,6 +73,7 @@ ComputeVoronoi::ComputeVoronoi(LAMMPS *lmp, int narg, char **arg) :
else if (strcmp(arg[iarg], "radius") == 0) { else if (strcmp(arg[iarg], "radius") == 0) {
if (iarg + 2 > narg || strstr(arg[iarg+1],"v_") != arg[iarg+1] ) if (iarg + 2 > narg || strstr(arg[iarg+1],"v_") != arg[iarg+1] )
error->all(FLERR,"Illegal compute voronoi/atom command"); error->all(FLERR,"Illegal compute voronoi/atom command");
delete[] radstr;
radstr = utils::strdup(&arg[iarg+1][2]); radstr = utils::strdup(&arg[iarg+1][2]);
iarg += 2; iarg += 2;
} }

View File

@ -125,6 +125,8 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) :
nhybrid_styles = hybrid->nstyles; nhybrid_styles = hybrid->nstyles;
// each hybrid sub-style needs to be assigned to a respa level // each hybrid sub-style needs to be assigned to a respa level
if (iarg + nhybrid_styles > narg) error->all(FLERR, "Illegal run_style respa command"); if (iarg + nhybrid_styles > narg) error->all(FLERR, "Illegal run_style respa command");
delete[] hybrid_level;
delete[] hybrid_compute;
hybrid_level = new int[nhybrid_styles]; hybrid_level = new int[nhybrid_styles];
hybrid_compute = new int[nhybrid_styles]; hybrid_compute = new int[nhybrid_styles];
for (int i = 0; i < nhybrid_styles; ++i) { for (int i = 0; i < nhybrid_styles; ++i) {