diff --git a/src/AMOEBA/amoeba_file.cpp b/src/AMOEBA/amoeba_file.cpp index 0b707047bf..99a8474a81 100644 --- a/src/AMOEBA/amoeba_file.cpp +++ b/src/AMOEBA/amoeba_file.cpp @@ -79,7 +79,7 @@ void PairAmoeba::read_prmfile(char *filename) int me = comm->me; FILE *fptr; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; if (me == 0) { fptr = utils::open_potential(filename, lmp, nullptr); @@ -179,8 +179,7 @@ void PairAmoeba::read_prmfile(char *filename) for (int i = 1; i <= n_amtype; i++) nmultiframe[i] = 0; } - char next[MAXLINE]; - next[0] = '\0'; + char next[MAXLINE] = {'\0'}; bool has_next = false; int n; while (true) { @@ -381,7 +380,7 @@ void PairAmoeba::read_keyfile(char *filename) int me = comm->me; FILE *fptr; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; if (me == 0) { fptr = utils::open_potential(filename, lmp, nullptr); if (fptr == nullptr) diff --git a/src/AMOEBA/fix_amoeba_bitorsion.cpp b/src/AMOEBA/fix_amoeba_bitorsion.cpp index 2a3618569f..f814f4109a 100644 --- a/src/AMOEBA/fix_amoeba_bitorsion.cpp +++ b/src/AMOEBA/fix_amoeba_bitorsion.cpp @@ -724,7 +724,7 @@ double FixAmoebaBiTorsion::compute_scalar() void FixAmoebaBiTorsion::read_grid_data(char *bitorsion_file) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; char *eof; FILE *fp = nullptr; diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index 58da1430b0..dbf053b407 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -616,8 +616,8 @@ int FixBocs::read_F_table( char *filename, int p_basis_type ) // Data file lines hold two floating point numbers. // Line length we allocate should be long enough without being too long. // 128 seems safe for a line we expect to be < 30 chars. - const int MAX_F_TABLE_LINE_LENGTH = 128; - char line[MAX_F_TABLE_LINE_LENGTH]; + constexpr int MAX_F_TABLE_LINE_LENGTH = 128; + char line[MAX_F_TABLE_LINE_LENGTH] = {'\0'}; std::vector inputLines; while (fgets(line, MAX_F_TABLE_LINE_LENGTH, fpi)) { inputLines.emplace_back(line); diff --git a/src/DPD-REACT/fix_eos_table.cpp b/src/DPD-REACT/fix_eos_table.cpp index 9e17ab450e..42567119df 100644 --- a/src/DPD-REACT/fix_eos_table.cpp +++ b/src/DPD-REACT/fix_eos_table.cpp @@ -194,7 +194,7 @@ void FixEOStable::free_table(Table *tb) void FixEOStable::read_table(Table *tb, Table *tb2, char *file, char *keyword) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; // open file diff --git a/src/DPD-REACT/fix_eos_table_rx.cpp b/src/DPD-REACT/fix_eos_table_rx.cpp index 24f57e399f..bf71b502f0 100644 --- a/src/DPD-REACT/fix_eos_table_rx.cpp +++ b/src/DPD-REACT/fix_eos_table_rx.cpp @@ -318,7 +318,8 @@ void FixEOStableRX::read_file(char *file) // one set of params can span multiple lines int n,nwords,ispecies; - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { @@ -414,7 +415,7 @@ void FixEOStableRX::free_table(Table *tb) void FixEOStableRX::read_table(Table *tb, Table *tb2, char *file, char *keyword) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; // open file diff --git a/src/DPD-REACT/fix_rx.cpp b/src/DPD-REACT/fix_rx.cpp index 43ff5bfe0e..96f8ec6a7d 100644 --- a/src/DPD-REACT/fix_rx.cpp +++ b/src/DPD-REACT/fix_rx.cpp @@ -250,7 +250,8 @@ void FixRX::post_constructor() // Assign species names to tmpspecies array and determine the number of unique species int n; - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; char * word; @@ -784,7 +785,8 @@ void FixRX::read_file(char *file) // Count the number of reactions from kinetics file int n,ispecies; - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { diff --git a/src/DPD-REACT/pair_exp6_rx.cpp b/src/DPD-REACT/pair_exp6_rx.cpp index d2294442ac..e0ac9c0b27 100644 --- a/src/DPD-REACT/pair_exp6_rx.cpp +++ b/src/DPD-REACT/pair_exp6_rx.cpp @@ -728,7 +728,8 @@ void PairExp6rx::read_file(char *file) // one set of params can span multiple lines int n,nwords,ispecies; - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { @@ -835,7 +836,8 @@ void PairExp6rx::read_file2(char *file) // one set of params can span multiple lines int n,nwords; - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { diff --git a/src/DPD-REACT/pair_multi_lucy.cpp b/src/DPD-REACT/pair_multi_lucy.cpp index 9810039c8f..a51e7b551e 100644 --- a/src/DPD-REACT/pair_multi_lucy.cpp +++ b/src/DPD-REACT/pair_multi_lucy.cpp @@ -344,7 +344,7 @@ double PairMultiLucy::init_one(int i, int j) void PairMultiLucy::read_table(Table *tb, char *file, char *keyword) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; // open file diff --git a/src/DPD-REACT/pair_multi_lucy_rx.cpp b/src/DPD-REACT/pair_multi_lucy_rx.cpp index e0ce3f62fb..4b61bf3a4d 100644 --- a/src/DPD-REACT/pair_multi_lucy_rx.cpp +++ b/src/DPD-REACT/pair_multi_lucy_rx.cpp @@ -483,7 +483,7 @@ double PairMultiLucyRX::init_one(int i, int j) void PairMultiLucyRX::read_table(Table *tb, char *file, char *keyword) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; // open file diff --git a/src/INTEL/pair_snap_intel.cpp b/src/INTEL/pair_snap_intel.cpp index 7cf5e00dcc..c9a4ed3d5a 100644 --- a/src/INTEL/pair_snap_intel.cpp +++ b/src/INTEL/pair_snap_intel.cpp @@ -445,7 +445,8 @@ void PairSNAPIntel::read_files(char *coefffilename, char *paramfilename) coefffilename, utils::getsyserror()); } - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int nwords = 0; while (nwords == 0) { diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index a8887ab275..c0ec0ee28e 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -281,7 +281,8 @@ void KimInteractions::KIM_SET_TYPE_PARAMETERS(const std::string &input_line) con if (fp == nullptr) error->one(FLERR, "Parameter file {} not found", filename); } - char line[MAXLINE], *ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int n, eof = 0; while (true) { diff --git a/src/KOKKOS/pair_exp6_rx_kokkos.cpp b/src/KOKKOS/pair_exp6_rx_kokkos.cpp index 3d3d9bf27f..dad7413669 100644 --- a/src/KOKKOS/pair_exp6_rx_kokkos.cpp +++ b/src/KOKKOS/pair_exp6_rx_kokkos.cpp @@ -1702,7 +1702,8 @@ void PairExp6rxKokkos::read_file(char *file) // one set of params can span multiple lines int n,nwords,ispecies; - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { diff --git a/src/ML-IAP/mliap_descriptor_snap.cpp b/src/ML-IAP/mliap_descriptor_snap.cpp index 1380c5c1ea..892dc8a004 100644 --- a/src/ML-IAP/mliap_descriptor_snap.cpp +++ b/src/ML-IAP/mliap_descriptor_snap.cpp @@ -380,7 +380,8 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) utils::getsyserror()); } - char line[MAXLINE], *ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int n; diff --git a/src/ML-IAP/mliap_descriptor_so3.cpp b/src/ML-IAP/mliap_descriptor_so3.cpp index 59b54cfee7..2308961913 100644 --- a/src/ML-IAP/mliap_descriptor_so3.cpp +++ b/src/ML-IAP/mliap_descriptor_so3.cpp @@ -90,7 +90,8 @@ void MLIAPDescriptorSO3::read_paramfile(char *paramfilename) utils::getsyserror()); } - char line[MAXLINE], *ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int n, nwords; diff --git a/src/ML-IAP/mliap_model.cpp b/src/ML-IAP/mliap_model.cpp index b23f02d343..c6df037c04 100644 --- a/src/ML-IAP/mliap_model.cpp +++ b/src/ML-IAP/mliap_model.cpp @@ -93,7 +93,8 @@ void MLIAPModelSimple::read_coeffs(char *coefffilename) utils::getsyserror()); } - char line[MAXLINE], *ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int n; diff --git a/src/ML-IAP/mliap_model_nn.cpp b/src/ML-IAP/mliap_model_nn.cpp index 685b0ce779..6695109f91 100644 --- a/src/ML-IAP/mliap_model_nn.cpp +++ b/src/ML-IAP/mliap_model_nn.cpp @@ -75,7 +75,8 @@ void MLIAPModelNN::read_coeffs(char *coefffilename) utils::getsyserror()); } - char line[MAXLINE], *ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int n, eof = 0, nwords = 0; while (nwords == 0) { if (comm->me == 0) { diff --git a/src/ML-POD/fitpod_command.cpp b/src/ML-POD/fitpod_command.cpp index 9ffb057173..ef39962e0b 100644 --- a/src/ML-POD/fitpod_command.cpp +++ b/src/ML-POD/fitpod_command.cpp @@ -150,7 +150,8 @@ int FitPOD::read_data_file(double *fitting_weights, std::string &file_format, // loop through lines of training data file and parse keywords - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { if (comm->me == 0) { @@ -251,7 +252,8 @@ int FitPOD::get_number_atom_exyz(std::vector& num_atom, int& num_atom_sum, error->one(FLERR,"Cannot open POD coefficient file {}: ", filename, utils::getsyserror()); } - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int num_configs = 0; num_atom_sum = 0; @@ -323,7 +325,8 @@ void FitPOD::read_exyz_file(double *lattice, double *stress, double *energy, dou error->one(FLERR,"Cannot open POD coefficient file {}: ", filename, utils::getsyserror()); } - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int cfi = 0; int nat = 0; diff --git a/src/ML-POD/mlpod.cpp b/src/ML-POD/mlpod.cpp index fba780bfae..088b9abadc 100644 --- a/src/ML-POD/mlpod.cpp +++ b/src/ML-POD/mlpod.cpp @@ -302,7 +302,8 @@ void MLPOD::read_pod(const std::string &pod_file) // loop through lines of POD file and parse keywords - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; while (true) { if (comm->me == 0) { @@ -639,7 +640,8 @@ void MLPOD::read_coeff_file(const std::string &coeff_file) // check format for first line of file - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int nwords = 0; while (nwords == 0) { diff --git a/src/ML-RANN/pair_rann.cpp b/src/ML-RANN/pair_rann.cpp index aa3578f2c9..4ec1f45703 100644 --- a/src/ML-RANN/pair_rann.cpp +++ b/src/ML-RANN/pair_rann.cpp @@ -616,7 +616,8 @@ void PairRANN::read_weight(std::vector line,std::vector line,std::vector line1,FILE* fp,char *filename,int *linenum) { int i,j,l; - char linetemp[MAXLINE],*ptr; + char linetemp[MAXLINE] = {'\0'}; + char *ptr; for (l=0;lone(filename,*linenum-1,"networklayers must be defined before biases."); diff --git a/src/ML-SNAP/pair_snap.cpp b/src/ML-SNAP/pair_snap.cpp index 245ff4acc4..f0fcd5c4e7 100644 --- a/src/ML-SNAP/pair_snap.cpp +++ b/src/ML-SNAP/pair_snap.cpp @@ -475,7 +475,8 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename) coefffilename, utils::getsyserror()); } - char line[MAXLINE],*ptr; + char line[MAXLINE] = {'\0'}; + char *ptr; int eof = 0; int nwords = 0; while (nwords == 0) { diff --git a/src/PHONON/fix_phonon.cpp b/src/PHONON/fix_phonon.cpp index 7787cefd6e..9ed39bc861 100644 --- a/src/PHONON/fix_phonon.cpp +++ b/src/PHONON/fix_phonon.cpp @@ -555,7 +555,7 @@ void FixPhonon::readmap() } // read from map file for others - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; FILE *fp = fopen(mapfile, "r"); if (fp == nullptr) error->all(FLERR,"Cannot open input map file {}: {}", mapfile, utils::getsyserror()); diff --git a/src/REACTION/fix_bond_react.cpp b/src/REACTION/fix_bond_react.cpp index e528ad30c7..34a5d3bcec 100644 --- a/src/REACTION/fix_bond_react.cpp +++ b/src/REACTION/fix_bond_react.cpp @@ -3922,7 +3922,8 @@ read map file void FixBondReact::read_map_file(int myrxn) { int rv; - char line[MAXLINE],keyword[MAXLINE]; + char line[MAXLINE] = {'\0'}; + char keyword[MAXLINE] = {'\0'}; char *eof,*ptr; // skip 1st line of file diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 5ab2a14137..8ee8fe303c 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -437,7 +437,7 @@ void NEB::readfile(char *file, int flag) int i, nchunk, eofflag, nlines; tagint tag; char *eof, *start, *next, *buf; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; double delx, dely, delz; if (me_universe == 0 && universe->uscreen) diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index bd3c53e3ec..7a63c52220 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -2300,7 +2300,7 @@ void FixRigid::readfile(int which, double *vec, double **array1, double **array2 int nlines; FILE *fp; char *eof,*start,*next,*buf; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; // open file and read and parse first non-empty, non-comment line containing the number of bodies if (comm->me == 0) { diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 5905e44595..487e3ee308 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -2470,7 +2470,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) int nchunk,eofflag,nlines,xbox,ybox,zbox; FILE *fp; char *eof,*start,*next,*buf; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; // create local hash with key/value pairs // key = mol ID of bodies my atoms own diff --git a/src/SPIN/neb_spin.cpp b/src/SPIN/neb_spin.cpp index de680cd1e7..ac54f069a9 100644 --- a/src/SPIN/neb_spin.cpp +++ b/src/SPIN/neb_spin.cpp @@ -375,7 +375,7 @@ void NEBSpin::readfile(char *file, int flag) int i,nchunk,eofflag,nlines; tagint tag; char *eof,*start,*next,*buf; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; double musp,xx,yy,zz,spx,spy,spz; if (me_universe == 0 && universe->uscreen) diff --git a/src/angle_write.cpp b/src/angle_write.cpp index 62e780b32e..0a0c457000 100644 --- a/src/angle_write.cpp +++ b/src/angle_write.cpp @@ -147,7 +147,7 @@ void AngleWrite::command(int narg, char **arg) writer->input->one("mass * 1.0"); writer->input->one(fmt::format("angle_style {}", force->angle_style)); FILE *coeffs; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; coeffs = fopen(coeffs_file.c_str(), "r"); for (int i = 0; i < atom->nangletypes; ++i) { fgets(line, MAXLINE, coeffs); diff --git a/src/dihedral_write.cpp b/src/dihedral_write.cpp index ace1de309d..375373523b 100644 --- a/src/dihedral_write.cpp +++ b/src/dihedral_write.cpp @@ -148,7 +148,7 @@ void DihedralWrite::command(int narg, char **arg) writer->input->one("mass * 1.0"); writer->input->one(fmt::format("dihedral_style {}", force->dihedral_style)); FILE *coeffs; - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; coeffs = fopen(coeffs_file.c_str(), "r"); for (int i = 0; i < atom->ndihedraltypes; ++i) { fgets(line, MAXLINE, coeffs); diff --git a/src/molecule.cpp b/src/molecule.cpp index 59f84154db..d0c8e793b3 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -416,7 +416,7 @@ void Molecule::compute_inertia() void Molecule::read(int flag) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; char *eof; // skip 1st line of file @@ -2134,7 +2134,7 @@ void Molecule::readline(char *line) std::string Molecule::parse_keyword(int flag, char *line) { - char line2[MAXLINE]; + char line2[MAXLINE] = {'\0'}; if (flag) { // read upto non-blank line plus 1 following line diff --git a/src/procmap.cpp b/src/procmap.cpp index 37f1fa3889..71e1cf5a6b 100644 --- a/src/procmap.cpp +++ b/src/procmap.cpp @@ -282,7 +282,7 @@ void ProcMap::custom_grid(char *cfile, int nprocs, int me; MPI_Comm_rank(world,&me); - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; FILE *fp = nullptr; if (me == 0) { diff --git a/src/universe.cpp b/src/universe.cpp index 69e96aaa9e..edd5b01031 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -69,7 +69,7 @@ Universe::~Universe() void Universe::reorder(char *style, char *arg) { - char line[MAXLINE]; + char line[MAXLINE] = {'\0'}; if (uworld != uorig) MPI_Comm_free(&uworld);