initialize static string buffers to empty strings

This commit is contained in:
Axel Kohlmeyer
2024-01-19 00:02:50 -05:00
parent 3ae4779c7f
commit 4015d1bb39
31 changed files with 61 additions and 42 deletions

View File

@ -79,7 +79,7 @@ void PairAmoeba::read_prmfile(char *filename)
int me = comm->me; int me = comm->me;
FILE *fptr; FILE *fptr;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
if (me == 0) { if (me == 0) {
fptr = utils::open_potential(filename, lmp, nullptr); 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; for (int i = 1; i <= n_amtype; i++) nmultiframe[i] = 0;
} }
char next[MAXLINE]; char next[MAXLINE] = {'\0'};
next[0] = '\0';
bool has_next = false; bool has_next = false;
int n; int n;
while (true) { while (true) {
@ -381,7 +380,7 @@ void PairAmoeba::read_keyfile(char *filename)
int me = comm->me; int me = comm->me;
FILE *fptr; FILE *fptr;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
if (me == 0) { if (me == 0) {
fptr = utils::open_potential(filename, lmp, nullptr); fptr = utils::open_potential(filename, lmp, nullptr);
if (fptr == nullptr) if (fptr == nullptr)

View File

@ -724,7 +724,7 @@ double FixAmoebaBiTorsion::compute_scalar()
void FixAmoebaBiTorsion::read_grid_data(char *bitorsion_file) void FixAmoebaBiTorsion::read_grid_data(char *bitorsion_file)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
char *eof; char *eof;
FILE *fp = nullptr; FILE *fp = nullptr;

View File

@ -616,8 +616,8 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
// Data file lines hold two floating point numbers. // Data file lines hold two floating point numbers.
// Line length we allocate should be long enough without being too long. // Line length we allocate should be long enough without being too long.
// 128 seems safe for a line we expect to be < 30 chars. // 128 seems safe for a line we expect to be < 30 chars.
const int MAX_F_TABLE_LINE_LENGTH = 128; constexpr int MAX_F_TABLE_LINE_LENGTH = 128;
char line[MAX_F_TABLE_LINE_LENGTH]; char line[MAX_F_TABLE_LINE_LENGTH] = {'\0'};
std::vector<std::string> inputLines; std::vector<std::string> inputLines;
while (fgets(line, MAX_F_TABLE_LINE_LENGTH, fpi)) { while (fgets(line, MAX_F_TABLE_LINE_LENGTH, fpi)) {
inputLines.emplace_back(line); inputLines.emplace_back(line);

View File

@ -194,7 +194,7 @@ void FixEOStable::free_table(Table *tb)
void FixEOStable::read_table(Table *tb, Table *tb2, char *file, char *keyword) void FixEOStable::read_table(Table *tb, Table *tb2, char *file, char *keyword)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
// open file // open file

View File

@ -318,7 +318,8 @@ void FixEOStableRX::read_file(char *file)
// one set of params can span multiple lines // one set of params can span multiple lines
int n,nwords,ispecies; int n,nwords,ispecies;
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {
@ -414,7 +415,7 @@ void FixEOStableRX::free_table(Table *tb)
void FixEOStableRX::read_table(Table *tb, Table *tb2, char *file, char *keyword) void FixEOStableRX::read_table(Table *tb, Table *tb2, char *file, char *keyword)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
// open file // open file

View File

@ -250,7 +250,8 @@ void FixRX::post_constructor()
// Assign species names to tmpspecies array and determine the number of unique species // Assign species names to tmpspecies array and determine the number of unique species
int n; int n;
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
char * word; char * word;
@ -784,7 +785,8 @@ void FixRX::read_file(char *file)
// Count the number of reactions from kinetics file // Count the number of reactions from kinetics file
int n,ispecies; int n,ispecies;
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {

View File

@ -728,7 +728,8 @@ void PairExp6rx::read_file(char *file)
// one set of params can span multiple lines // one set of params can span multiple lines
int n,nwords,ispecies; int n,nwords,ispecies;
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {
@ -835,7 +836,8 @@ void PairExp6rx::read_file2(char *file)
// one set of params can span multiple lines // one set of params can span multiple lines
int n,nwords; int n,nwords;
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {

View File

@ -344,7 +344,7 @@ double PairMultiLucy::init_one(int i, int j)
void PairMultiLucy::read_table(Table *tb, char *file, char *keyword) void PairMultiLucy::read_table(Table *tb, char *file, char *keyword)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
// open file // open file

View File

@ -483,7 +483,7 @@ double PairMultiLucyRX::init_one(int i, int j)
void PairMultiLucyRX::read_table(Table *tb, char *file, char *keyword) void PairMultiLucyRX::read_table(Table *tb, char *file, char *keyword)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
// open file // open file

View File

@ -445,7 +445,8 @@ void PairSNAPIntel::read_files(char *coefffilename, char *paramfilename)
coefffilename, utils::getsyserror()); coefffilename, utils::getsyserror());
} }
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
int nwords = 0; int nwords = 0;
while (nwords == 0) { while (nwords == 0) {

View File

@ -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); 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; int n, eof = 0;
while (true) { while (true) {

View File

@ -1702,7 +1702,8 @@ void PairExp6rxKokkos<DeviceType>::read_file(char *file)
// one set of params can span multiple lines // one set of params can span multiple lines
int n,nwords,ispecies; int n,nwords,ispecies;
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {

View File

@ -380,7 +380,8 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename)
utils::getsyserror()); utils::getsyserror());
} }
char line[MAXLINE], *ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
int n; int n;

View File

@ -90,7 +90,8 @@ void MLIAPDescriptorSO3::read_paramfile(char *paramfilename)
utils::getsyserror()); utils::getsyserror());
} }
char line[MAXLINE], *ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
int n, nwords; int n, nwords;

View File

@ -93,7 +93,8 @@ void MLIAPModelSimple::read_coeffs(char *coefffilename)
utils::getsyserror()); utils::getsyserror());
} }
char line[MAXLINE], *ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
int n; int n;

View File

@ -75,7 +75,8 @@ void MLIAPModelNN::read_coeffs(char *coefffilename)
utils::getsyserror()); utils::getsyserror());
} }
char line[MAXLINE], *ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int n, eof = 0, nwords = 0; int n, eof = 0, nwords = 0;
while (nwords == 0) { while (nwords == 0) {
if (comm->me == 0) { if (comm->me == 0) {

View File

@ -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 // loop through lines of training data file and parse keywords
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {
if (comm->me == 0) { if (comm->me == 0) {
@ -251,7 +252,8 @@ int FitPOD::get_number_atom_exyz(std::vector<int>& num_atom, int& num_atom_sum,
error->one(FLERR,"Cannot open POD coefficient file {}: ", filename, utils::getsyserror()); 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 eof = 0;
int num_configs = 0; int num_configs = 0;
num_atom_sum = 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()); 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 eof = 0;
int cfi = 0; int cfi = 0;
int nat = 0; int nat = 0;

View File

@ -302,7 +302,8 @@ void MLPOD::read_pod(const std::string &pod_file)
// loop through lines of POD file and parse keywords // loop through lines of POD file and parse keywords
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
while (true) { while (true) {
if (comm->me == 0) { 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 // check format for first line of file
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
int nwords = 0; int nwords = 0;
while (nwords == 0) { while (nwords == 0) {

View File

@ -616,7 +616,8 @@ void PairRANN::read_weight(std::vector<std::string> line,std::vector<std::string
void PairRANN::read_bias(std::vector<std::string> line,std::vector<std::string> line1,FILE* fp,char *filename,int *linenum) { void PairRANN::read_bias(std::vector<std::string> line,std::vector<std::string> line1,FILE* fp,char *filename,int *linenum) {
int i,j,l; int i,j,l;
char linetemp[MAXLINE],*ptr; char linetemp[MAXLINE] = {'\0'};
char *ptr;
for (l=0;l<nelements;l++) { for (l=0;l<nelements;l++) {
if (line[1].compare(elements[l])==0) { if (line[1].compare(elements[l])==0) {
if (net[l].layers==0)error->one(filename,*linenum-1,"networklayers must be defined before biases."); if (net[l].layers==0)error->one(filename,*linenum-1,"networklayers must be defined before biases.");

View File

@ -475,7 +475,8 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename)
coefffilename, utils::getsyserror()); coefffilename, utils::getsyserror());
} }
char line[MAXLINE],*ptr; char line[MAXLINE] = {'\0'};
char *ptr;
int eof = 0; int eof = 0;
int nwords = 0; int nwords = 0;
while (nwords == 0) { while (nwords == 0) {

View File

@ -555,7 +555,7 @@ void FixPhonon::readmap()
} }
// read from map file for others // read from map file for others
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
FILE *fp = fopen(mapfile, "r"); FILE *fp = fopen(mapfile, "r");
if (fp == nullptr) if (fp == nullptr)
error->all(FLERR,"Cannot open input map file {}: {}", mapfile, utils::getsyserror()); error->all(FLERR,"Cannot open input map file {}: {}", mapfile, utils::getsyserror());

View File

@ -3922,7 +3922,8 @@ read map file
void FixBondReact::read_map_file(int myrxn) void FixBondReact::read_map_file(int myrxn)
{ {
int rv; int rv;
char line[MAXLINE],keyword[MAXLINE]; char line[MAXLINE] = {'\0'};
char keyword[MAXLINE] = {'\0'};
char *eof,*ptr; char *eof,*ptr;
// skip 1st line of file // skip 1st line of file

View File

@ -437,7 +437,7 @@ void NEB::readfile(char *file, int flag)
int i, nchunk, eofflag, nlines; int i, nchunk, eofflag, nlines;
tagint tag; tagint tag;
char *eof, *start, *next, *buf; char *eof, *start, *next, *buf;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
double delx, dely, delz; double delx, dely, delz;
if (me_universe == 0 && universe->uscreen) if (me_universe == 0 && universe->uscreen)

View File

@ -2300,7 +2300,7 @@ void FixRigid::readfile(int which, double *vec, double **array1, double **array2
int nlines; int nlines;
FILE *fp; FILE *fp;
char *eof,*start,*next,*buf; 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 // open file and read and parse first non-empty, non-comment line containing the number of bodies
if (comm->me == 0) { if (comm->me == 0) {

View File

@ -2470,7 +2470,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody)
int nchunk,eofflag,nlines,xbox,ybox,zbox; int nchunk,eofflag,nlines,xbox,ybox,zbox;
FILE *fp; FILE *fp;
char *eof,*start,*next,*buf; char *eof,*start,*next,*buf;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
// create local hash with key/value pairs // create local hash with key/value pairs
// key = mol ID of bodies my atoms own // key = mol ID of bodies my atoms own

View File

@ -375,7 +375,7 @@ void NEBSpin::readfile(char *file, int flag)
int i,nchunk,eofflag,nlines; int i,nchunk,eofflag,nlines;
tagint tag; tagint tag;
char *eof,*start,*next,*buf; char *eof,*start,*next,*buf;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
double musp,xx,yy,zz,spx,spy,spz; double musp,xx,yy,zz,spx,spy,spz;
if (me_universe == 0 && universe->uscreen) if (me_universe == 0 && universe->uscreen)

View File

@ -147,7 +147,7 @@ void AngleWrite::command(int narg, char **arg)
writer->input->one("mass * 1.0"); writer->input->one("mass * 1.0");
writer->input->one(fmt::format("angle_style {}", force->angle_style)); writer->input->one(fmt::format("angle_style {}", force->angle_style));
FILE *coeffs; FILE *coeffs;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
coeffs = fopen(coeffs_file.c_str(), "r"); coeffs = fopen(coeffs_file.c_str(), "r");
for (int i = 0; i < atom->nangletypes; ++i) { for (int i = 0; i < atom->nangletypes; ++i) {
fgets(line, MAXLINE, coeffs); fgets(line, MAXLINE, coeffs);

View File

@ -148,7 +148,7 @@ void DihedralWrite::command(int narg, char **arg)
writer->input->one("mass * 1.0"); writer->input->one("mass * 1.0");
writer->input->one(fmt::format("dihedral_style {}", force->dihedral_style)); writer->input->one(fmt::format("dihedral_style {}", force->dihedral_style));
FILE *coeffs; FILE *coeffs;
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
coeffs = fopen(coeffs_file.c_str(), "r"); coeffs = fopen(coeffs_file.c_str(), "r");
for (int i = 0; i < atom->ndihedraltypes; ++i) { for (int i = 0; i < atom->ndihedraltypes; ++i) {
fgets(line, MAXLINE, coeffs); fgets(line, MAXLINE, coeffs);

View File

@ -416,7 +416,7 @@ void Molecule::compute_inertia()
void Molecule::read(int flag) void Molecule::read(int flag)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
char *eof; char *eof;
// skip 1st line of file // skip 1st line of file
@ -2134,7 +2134,7 @@ void Molecule::readline(char *line)
std::string Molecule::parse_keyword(int flag, char *line) std::string Molecule::parse_keyword(int flag, char *line)
{ {
char line2[MAXLINE]; char line2[MAXLINE] = {'\0'};
if (flag) { if (flag) {
// read upto non-blank line plus 1 following line // read upto non-blank line plus 1 following line

View File

@ -282,7 +282,7 @@ void ProcMap::custom_grid(char *cfile, int nprocs,
int me; int me;
MPI_Comm_rank(world,&me); MPI_Comm_rank(world,&me);
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
FILE *fp = nullptr; FILE *fp = nullptr;
if (me == 0) { if (me == 0) {

View File

@ -69,7 +69,7 @@ Universe::~Universe()
void Universe::reorder(char *style, char *arg) void Universe::reorder(char *style, char *arg)
{ {
char line[MAXLINE]; char line[MAXLINE] = {'\0'};
if (uworld != uorig) MPI_Comm_free(&uworld); if (uworld != uorig) MPI_Comm_free(&uworld);