no if statement required before delete[]

This commit is contained in:
Axel Kohlmeyer
2022-04-10 19:55:24 -04:00
parent 3eec2eec9a
commit 74f2b67b1a
20 changed files with 46 additions and 46 deletions

View File

@ -43,7 +43,7 @@ FixDrudeTransform<inverse>::FixDrudeTransform(LAMMPS *lmp, int narg, char **arg)
template <bool inverse> template <bool inverse>
FixDrudeTransform<inverse>::~FixDrudeTransform() FixDrudeTransform<inverse>::~FixDrudeTransform()
{ {
if (mcoeff) delete [] mcoeff; delete[] mcoeff;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -65,7 +65,7 @@ FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
FixOneWay::~FixOneWay() FixOneWay::~FixOneWay()
{ {
if (regionstr) delete[] regionstr; delete[] regionstr;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -52,16 +52,16 @@ DihedralSpherical::~DihedralSpherical()
memory->destroy(nterms); memory->destroy(nterms);
for (int i = 1; i <= atom->ndihedraltypes; i++) { for (int i = 1; i <= atom->ndihedraltypes; i++) {
if (Ccoeff[i]) delete[] Ccoeff[i]; delete[] Ccoeff[i];
if (phi_mult[i]) delete[] phi_mult[i]; delete[] phi_mult[i];
if (phi_shift[i]) delete[] phi_shift[i]; delete[] phi_shift[i];
if (phi_offset[i]) delete[] phi_offset[i]; delete[] phi_offset[i];
if (theta1_mult[i]) delete[] theta1_mult[i]; delete[] theta1_mult[i];
if (theta1_shift[i]) delete[] theta1_shift[i]; delete[] theta1_shift[i];
if (theta1_offset[i]) delete[] theta1_offset[i]; delete[] theta1_offset[i];
if (theta2_mult[i]) delete[] theta2_mult[i]; delete[] theta2_mult[i];
if (theta2_shift[i]) delete[] theta2_shift[i]; delete[] theta2_shift[i];
if (theta2_offset[i]) delete[] theta2_offset[i]; delete[] theta2_offset[i];
} }
delete[] Ccoeff; delete[] Ccoeff;
delete[] phi_mult; delete[] phi_mult;

View File

@ -44,7 +44,7 @@ NPairSkipIntel::NPairSkipIntel(LAMMPS *lmp) : NPair(lmp) {
NPairSkipIntel::~NPairSkipIntel() { NPairSkipIntel::~NPairSkipIntel() {
delete []_inum_starts; delete []_inum_starts;
delete []_inum_counts; delete []_inum_counts;
if (_full_props) delete []_full_props; delete[] _full_props;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -1375,7 +1375,7 @@ void PPPMDisp::init_coeffs()
// check if the function should preferably be [1] or [2] or [3] // check if the function should preferably be [1] or [2] or [3]
if (nsplit == 1) { if (nsplit == 1) {
if (B) delete [] B; delete[] B;
function[3] = 0; function[3] = 0;
function[2] = 0; function[2] = 0;
function[1] = 1; function[1] = 1;
@ -1388,12 +1388,12 @@ void PPPMDisp::init_coeffs()
utils::logmesg(lmp," Using {} instead of 7 structure factors\n",nsplit); utils::logmesg(lmp," Using {} instead of 7 structure factors\n",nsplit);
//function[3] = 1; //function[3] = 1;
//function[2] = 0; //function[2] = 0;
if (B) delete [] B; // remove this when un-comment previous 2 lines delete[] B; // remove this when un-comment previous 2 lines
} }
if (function[2] && (nsplit > 6)) { if (function[2] && (nsplit > 6)) {
if (me == 0) utils::logmesg(lmp," Using 7 structure factors\n"); if (me == 0) utils::logmesg(lmp," Using 7 structure factors\n");
if (B) delete [] B; delete[] B;
} }
if (function[3]) { if (function[3]) {

View File

@ -165,8 +165,8 @@ FixNVEManifoldRattle::~FixNVEManifoldRattle()
} }
if (tvars ) delete [] tvars; if (tvars ) delete [] tvars;
if (tstyle) delete [] tstyle; delete[] tstyle;
if (is_var) delete [] is_var; delete[] is_var;
} }

View File

@ -159,13 +159,13 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg,
FixNVTManifoldRattle::~FixNVTManifoldRattle() FixNVTManifoldRattle::~FixNVTManifoldRattle()
{ {
// Deallocate heap-allocated objects. // Deallocate heap-allocated objects.
if (eta) delete[] eta; delete[] eta;
if (eta_dot) delete[] eta_dot; delete[] eta_dot;
if (eta_dotdot) delete[] eta_dotdot; delete[] eta_dotdot;
if (eta_mass) delete[] eta_mass; delete[] eta_mass;
modify->delete_compute(id_temp); modify->delete_compute(id_temp);
if (id_temp) delete[] id_temp; delete[] id_temp;
} }
int FixNVTManifoldRattle::setmask() int FixNVTManifoldRattle::setmask()

View File

@ -321,9 +321,9 @@ void FixPlumed::post_force(int /* vflag */)
if (nlocal != atom->nlocal) { if (nlocal != atom->nlocal) {
if (charges) delete [] charges; delete[] charges;
if (masses) delete [] masses; delete[] masses;
if (gatindex) delete [] gatindex; delete[] gatindex;
nlocal=atom->nlocal; nlocal=atom->nlocal;
gatindex=new int [nlocal]; gatindex=new int [nlocal];

View File

@ -232,7 +232,7 @@ FixReaxFFSpecies::~FixReaxFFSpecies()
memory->destroy(MolType); memory->destroy(MolType);
memory->destroy(MolName); memory->destroy(MolName);
if (filepos) delete[] filepos; delete[] filepos;
if (me == 0) { if (me == 0) {
if (compressed) if (compressed)

View File

@ -615,7 +615,7 @@ void FixPIMD::comm_init()
if (buf_beads) { if (buf_beads) {
for (int i = 0; i < np; i++) for (int i = 0; i < np; i++)
if (buf_beads[i]) delete[] buf_beads[i]; delete[] buf_beads[i];
delete[] buf_beads; delete[] buf_beads;
} }

View File

@ -172,7 +172,7 @@ FixRigidNH::~FixRigidNH()
deallocate_order(); deallocate_order();
} }
if (rfix) delete [] rfix; delete[] rfix;
if (tcomputeflag) modify->delete_compute(id_temp); if (tcomputeflag) modify->delete_compute(id_temp);
delete [] id_temp; delete [] id_temp;
@ -303,7 +303,7 @@ void FixRigidNH::init()
// rfix[] = indices to each fix rigid // rfix[] = indices to each fix rigid
// this will include self // this will include self
if (rfix) delete [] rfix; delete[] rfix;
nrigidfix = 0; nrigidfix = 0;
rfix = nullptr; rfix = nullptr;

View File

@ -184,7 +184,7 @@ FixRigidNHSmall::~FixRigidNHSmall()
deallocate_order(); deallocate_order();
} }
if (rfix) delete [] rfix; delete[] rfix;
if (tcomputeflag) modify->delete_compute(id_temp); if (tcomputeflag) modify->delete_compute(id_temp);
delete [] id_temp; delete [] id_temp;
@ -301,7 +301,7 @@ void FixRigidNHSmall::init()
// rfix[] = indices to each fix rigid // rfix[] = indices to each fix rigid
// this will include self // this will include self
if (rfix) delete [] rfix; delete[] rfix;
nrigidfix = 0; nrigidfix = 0;
rfix = nullptr; rfix = nullptr;

View File

@ -1740,7 +1740,7 @@ int DumpCustom::modify_param(int narg, char **arg)
int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1; int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1;
if (i < 0 || i >= nfield) if (i < 0 || i >= nfield)
error->all(FLERR,"Illegal dump_modify command"); error->all(FLERR,"Illegal dump_modify command");
if (format_column_user[i]) delete[] format_column_user[i]; delete[] format_column_user[i];
format_column_user[i] = utils::strdup(arg[2]); format_column_user[i] = utils::strdup(arg[2]);
} }
return 3; return 3;

View File

@ -257,7 +257,7 @@ int DumpLocal::modify_param(int narg, char **arg)
int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1; int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1;
if (i < 0 || i >= nfield) if (i < 0 || i >= nfield)
error->all(FLERR,"Illegal dump_modify command"); error->all(FLERR,"Illegal dump_modify command");
if (format_column_user[i]) delete[] format_column_user[i]; delete[] format_column_user[i];
format_column_user[i] = utils::strdup(arg[2]); format_column_user[i] = utils::strdup(arg[2]);
} }
return 3; return 3;

View File

@ -41,7 +41,7 @@ DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg),
sort_flag = 1; sort_flag = 1;
sortcol = 0; sortcol = 0;
if (format_default) delete [] format_default; delete[] format_default;
format_default = utils::strdup("%s %g %g %g"); format_default = utils::strdup("%s %g %g %g");

View File

@ -223,7 +223,7 @@ void Force::create_pair(const std::string &style, int trysuffix)
{ {
delete[] pair_style; delete[] pair_style;
if (pair) delete pair; if (pair) delete pair;
if (pair_restart) delete[] pair_restart; delete[] pair_restart;
pair_style = nullptr; pair_style = nullptr;
pair = nullptr; pair = nullptr;
pair_restart = nullptr; pair_restart = nullptr;

View File

@ -168,7 +168,7 @@ Input::~Input()
memory->sfree(line); memory->sfree(line);
memory->sfree(copy); memory->sfree(copy);
memory->sfree(work); memory->sfree(work);
if (labelstr) delete[] labelstr; delete[] labelstr;
memory->sfree(arg); memory->sfree(arg);
delete[] infiles; delete[] infiles;
delete variable; delete variable;
@ -1026,7 +1026,7 @@ void Input::jump()
if (narg == 2) { if (narg == 2) {
label_active = 1; label_active = 1;
if (labelstr) delete[] labelstr; delete[] labelstr;
labelstr = utils::strdup(arg[1]); labelstr = utils::strdup(arg[1]);
} }
} }

View File

@ -51,8 +51,8 @@ PairHybrid::~PairHybrid()
for (int m = 0; m < nstyles; m++) { for (int m = 0; m < nstyles; m++) {
delete styles[m]; delete styles[m];
delete[] keywords[m]; delete[] keywords[m];
if (special_lj[m]) delete[] special_lj[m]; delete[] special_lj[m];
if (special_coul[m]) delete[] special_coul[m]; delete[] special_coul[m];
} }
} }
delete[] styles; delete[] styles;
@ -275,8 +275,8 @@ void PairHybrid::settings(int narg, char **arg)
for (int m = 0; m < nstyles; m++) { for (int m = 0; m < nstyles; m++) {
delete styles[m]; delete styles[m];
delete[] keywords[m]; delete[] keywords[m];
if (special_lj[m]) delete[] special_lj[m]; delete[] special_lj[m];
if (special_coul[m]) delete[] special_coul[m]; delete[] special_coul[m];
} }
delete[] styles; delete[] styles;
delete[] keywords; delete[] keywords;

View File

@ -250,8 +250,8 @@ void PairHybridScaled::settings(int narg, char **arg)
for (int m = 0; m < nstyles; m++) { for (int m = 0; m < nstyles; m++) {
delete styles[m]; delete styles[m];
delete[] keywords[m]; delete[] keywords[m];
if (special_lj[m]) delete[] special_lj[m]; delete[] special_lj[m];
if (special_coul[m]) delete[] special_coul[m]; delete[] special_coul[m];
} }
delete[] styles; delete[] styles;
delete[] keywords; delete[] keywords;

View File

@ -226,7 +226,7 @@ int main(int narg, char **arg)
// extend buffer to fit chunk size // extend buffer to fit chunk size
if (n > maxbuf) { if (n > maxbuf) {
if (buf) delete[] buf; delete[] buf;
buf = new double[n]; buf = new double[n];
maxbuf = n; maxbuf = n;
} }
@ -260,6 +260,6 @@ int main(int narg, char **arg)
unit_style = nullptr; unit_style = nullptr;
} }
if (buf) delete[] buf; delete[] buf;
return 0; return 0;
} }