diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 1aead7064447c3faa023bf7db237600f60cebfce..11ba4a41a5a5d20976f8c0f19fde7ca61c4ca620 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -225,7 +225,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : fp = fopen(arg[iarg+1],"w"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open fix ave/chunk file %s",arg[iarg+1]); + snprintf(str,128,"Cannot open fix ave/chunk file %s",arg[iarg+1]); error->one(FLERR,str); } } diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index 198caf151409301e2ca7308a7026ff1af79b3d39..5c95f20ec2eec92658465585f4dbce83eda498a7 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -149,7 +149,7 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): fp = fopen(arg[iarg+1],"w"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open fix ave/correlate file %s",arg[iarg+1]); + snprintf(str,128,"Cannot open fix ave/correlate file %s",arg[iarg+1]); error->one(FLERR,str); } } diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index ce32167b745ffbfe9374bdf3855b226cba79e550..a5bf8db557853771ebb077da829d522491c17d63 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -937,7 +937,7 @@ void FixAveHisto::options(int iarg, int narg, char **arg) fp = fopen(arg[iarg+1],"w"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open fix ave/histo file %s",arg[iarg+1]); + snprintf(str,128,"Cannot open fix ave/histo file %s",arg[iarg+1]); error->one(FLERR,str); } } diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 53354ee06617157de389060cce0e22f5cc4b8172..50654b6561a04027c695fa6e3e0a913064bd0950 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -1042,7 +1042,7 @@ void FixAveTime::options(int iarg, int narg, char **arg) fp = fopen(arg[iarg+1],"w"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open fix ave/time file %s",arg[iarg+1]); + snprintf(str,128,"Cannot open fix ave/time file %s",arg[iarg+1]); error->one(FLERR,str); } } diff --git a/src/fix_enforce2d.cpp b/src/fix_enforce2d.cpp index ef7eb3a0ef1a2972cb632bbee55e73e14f1ca77b..986ded5d16d10f859f10acd41cefcdc61fe33985 100644 --- a/src/fix_enforce2d.cpp +++ b/src/fix_enforce2d.cpp @@ -78,7 +78,7 @@ void FixEnforce2D::init() flist[nfixlist++] = modify->fix[i]; else { char msg[256]; - sprintf(msg,"Fix enforce2d must be defined after fix %s",modify->fix[i]->style); + snprintf(msg,256,"Fix enforce2d must be defined after fix %s",modify->fix[i]->style); error->all(FLERR,msg); } } diff --git a/src/fix_print.cpp b/src/fix_print.cpp index 16218e0088e7ab0d04c560bbb975bdace7d41ebd..969fcf8140b2f25eefaba582940ce822ec720fc8 100644 --- a/src/fix_print.cpp +++ b/src/fix_print.cpp @@ -60,7 +60,7 @@ FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) : else fp = fopen(arg[iarg+1],"a"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open fix print file %s",arg[iarg+1]); + snprintf(str,128,"Cannot open fix print file %s",arg[iarg+1]); error->one(FLERR,str); } } diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 5b12b6def21bf29b71c113929a6ff23ca2de7b95..c89419f85014de0b089c2823b0b0730abf8d5fa9 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -224,7 +224,7 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, if (nwords != nvalue+1) { char str[128]; - sprintf(str,"Incorrect %s format in data file",keyword); + snprintf(str,128,"Incorrect %s format in data file",keyword); error->all(FLERR,str); } @@ -242,7 +242,7 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, values[0] = strtok(buf," \t\n\r\f"); if (values[0] == NULL) { char str[128]; - sprintf(str,"Too few lines in %s section of data file",keyword); + snprintf(str,128,"Too few lines in %s section of data file",keyword); error->one(FLERR,str); } int format_ok = 1; @@ -252,14 +252,14 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, } if (!format_ok) { char str[128]; - sprintf(str,"Incorrect %s format in data file",keyword); + snprintf(str,128,"Incorrect %s format in data file",keyword); error->all(FLERR,str); } itag = ATOTAGINT(values[0]) + id_offset; if (itag <= 0 || itag > map_tag_max) { char str[128]; - sprintf(str,"Invalid atom ID in %s section of data file",keyword); + snprintf(str,128,"Invalid atom ID in %s section of data file",keyword); error->one(FLERR,str); } diff --git a/src/fix_tmd.cpp b/src/fix_tmd.cpp index dd11dfd0c7dc3e917f83306c6aa0da7d6a59edb4..4cbb244bc01b5a38ca11828f81081bfa47e7fcea 100644 --- a/src/fix_tmd.cpp +++ b/src/fix_tmd.cpp @@ -75,7 +75,7 @@ nfileevery(0), fp(NULL), xf(NULL), xold(NULL) fp = fopen(arg[6],"w"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open fix tmd file %s",arg[6]); + snprintf(str,128,"Cannot open fix tmd file %s",arg[6]); error->one(FLERR,str); } fprintf(fp,"%s %s\n","# Step rho_target rho_old gamma_back", @@ -523,7 +523,7 @@ void FixTMD::open(char *file) else { #ifdef LAMMPS_GZIP char gunzip[128]; - sprintf(gunzip,"gzip -c -d %s",file); + snprintf(gunzip,128,"gzip -c -d %s",file); #ifdef _WIN32 fp = _popen(gunzip,"rb"); @@ -538,7 +538,7 @@ void FixTMD::open(char *file) if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open file %s",file); + snprintf(str,128,"Cannot open file %s",file); error->one(FLERR,str); } } diff --git a/src/force.cpp b/src/force.cpp index 8ee301982d168c6f5c8389bee86d3d2404bcf903..91fccd71978662e8e2ea7801a0e9831acb522214 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -182,8 +182,8 @@ void Force::init() if (pair_restart) { if (!pair) { char msg[128]; - sprintf(msg,"Must re-specify non-restarted pair style (%s) " - "after read_restart", pair_restart); + snprintf(msg,128,"Must re-specify non-restarted pair style (%s) " + "after read_restart", pair_restart); error->all(FLERR,msg); } } diff --git a/src/input.cpp b/src/input.cpp index f41c8458eae18e2b3200decaa69b0ff5c8b4fe22..2834e369131585a2b0d903f11250026bb8729419 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -267,7 +267,7 @@ void Input::file(const char *filename) infile = fopen(filename,"r"); if (infile == NULL) { char str[128]; - sprintf(str,"Cannot open input script %s",filename); + snprintf(str,128,"Cannot open input script %s",filename); error->one(FLERR,str); } infiles[0] = infile; @@ -526,7 +526,7 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) *fmtflag='\0'; } - sprintf(immediate,fmtstr,variable->compute_equal(var)); + snprintf(immediate,256,fmtstr,variable->compute_equal(var)); value = immediate; // single character variable name, e.g. $a @@ -541,7 +541,7 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) if (value == NULL) { char str[128]; - sprintf(str,"Substitution for illegal variable %s",var); + snprintf(str,128,"Substitution for illegal variable %s",var); error->one(FLERR,str); } // check if storage in str2 needs to be expanded @@ -1047,7 +1047,7 @@ void Input::include() infile = fopen(arg[0],"r"); if (infile == NULL) { char str[128]; - sprintf(str,"Cannot open input script %s",arg[0]); + snprintf(str,128,"Cannot open input script %s",arg[0]); error->one(FLERR,str); } infiles[nfile++] = infile; @@ -1072,7 +1072,7 @@ void Input::jump() infile = fopen(arg[0],"r"); if (infile == NULL) { char str[128]; - sprintf(str,"Cannot open input script %s",arg[0]); + snprintf(str,128,"Cannot open input script %s",arg[0]); error->one(FLERR,str); } infiles[nfile-1] = infile; @@ -1117,7 +1117,7 @@ void Input::log() if (logfile == NULL) { char str[128]; - sprintf(str,"Cannot open logfile %s",arg[0]); + snprintf(str,128,"Cannot open logfile %s",arg[0]); error->one(FLERR,str); } } @@ -1196,7 +1196,7 @@ void Input::print() else fp = fopen(arg[iarg+1],"a"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open print file %s",arg[iarg+1]); + snprintf(str,128,"Cannot open print file %s",arg[iarg+1]); error->one(FLERR,str); } } diff --git a/src/lammps.cpp b/src/lammps.cpp index fcdfecf30a83795d742504e43ae12a9e0dd7bdc3..04d8daa47883de4f63856813a655e784d40517a6 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -385,7 +385,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) else infile = fopen(arg[inflag],"r"); if (infile == NULL) { char str[128]; - sprintf(str,"Cannot open input script %s",arg[inflag]); + snprintf(str,128,"Cannot open input script %s",arg[inflag]); error->one(FLERR,str); } } @@ -416,7 +416,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) screen = NULL; else { char str[128]; - sprintf(str,"%s.%d",arg[screenflag],universe->iworld); + snprintf(str,128,"%s.%d",arg[screenflag],universe->iworld); screen = fopen(str,"w"); if (screen == NULL) error->one(FLERR,"Cannot open screen file"); } @@ -424,7 +424,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) screen = NULL; else { char str[128]; - sprintf(str,"%s.%d",arg[partscreenflag],universe->iworld); + snprintf(str,128,"%s.%d",arg[partscreenflag],universe->iworld); screen = fopen(str,"w"); if (screen == NULL) error->one(FLERR,"Cannot open screen file"); } else screen = NULL; @@ -440,7 +440,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) logfile = NULL; else { char str[128]; - sprintf(str,"%s.%d",arg[logflag],universe->iworld); + snprintf(str,128,"%s.%d",arg[logflag],universe->iworld); logfile = fopen(str,"w"); if (logfile == NULL) error->one(FLERR,"Cannot open logfile"); } @@ -448,7 +448,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) logfile = NULL; else { char str[128]; - sprintf(str,"%s.%d",arg[partlogflag],universe->iworld); + snprintf(str,128,"%s.%d",arg[partlogflag],universe->iworld); logfile = fopen(str,"w"); if (logfile == NULL) error->one(FLERR,"Cannot open logfile"); } else logfile = NULL; @@ -457,7 +457,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) infile = fopen(arg[inflag],"r"); if (infile == NULL) { char str[128]; - sprintf(str,"Cannot open input script %s",arg[inflag]); + snprintf(str,128,"Cannot open input script %s",arg[inflag]); error->one(FLERR,str); } } else infile = NULL; @@ -579,10 +579,10 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) if (restartflag) { char cmd[128]; - sprintf(cmd,"read_restart %s\n",rfile); + snprintf(cmd,128,"read_restart %s\n",rfile); if (restartremapflag) strcat(cmd," remap\n"); input->one(cmd); - sprintf(cmd,"write_data %s",dfile); + snprintf(cmd,128,"write_data %s",dfile); for (iarg = wdfirst; iarg < wdlast; iarg++) sprintf(&cmd[strlen(cmd)]," %s",arg[iarg]); strcat(cmd," noinit\n"); diff --git a/src/memory.cpp b/src/memory.cpp index 429cf75c00ab9975a7859201301c9e963b1bf1e8..7a23a230791c51f078b1195e7867dfb2d91c4739 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -121,6 +121,7 @@ void Memory::sfree(void *ptr) void Memory::fail(const char *name) { char str[128]; - sprintf(str,"Cannot create/grow a vector/array of pointers for %s",name); + snprintf(str,128, + "Cannot create/grow a vector/array of pointers for %s",name); error->one(FLERR,str); } diff --git a/src/modify.cpp b/src/modify.cpp index c5a680a3bd6b0e928db0c1f055fb63af3d58e468..8a0d1afa2c8db7a7194079b88903520b5b52bf96 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -239,7 +239,8 @@ void Modify::init() for (i = 0; i < nfix; i++) if (!fix[i]->dynamic_group_allow && group->dynamic[fix[i]->igroup]) { char str[128]; - sprintf(str,"Fix %s does not allow use of dynamic group",fix[i]->id); + snprintf(str,128, + "Fix %s does not allow use of dynamic group",fix[i]->id); error->all(FLERR,str); } @@ -247,7 +248,7 @@ void Modify::init() if (!compute[i]->dynamic_group_allow && group->dynamic[compute[i]->igroup]) { char str[128]; - sprintf(str,"Compute %s does not allow use of dynamic group",fix[i]->id); + snprintf(str,128,"Compute %s does not allow use of dynamic group",fix[i]->id); error->all(FLERR,str); } @@ -889,7 +890,7 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) if (fix[ifix] == NULL) { char str[128]; - sprintf(str,"Unknown fix style %s",arg[2]); + snprintf(str,128,"Unknown fix style %s",arg[2]); error->all(FLERR,str); } @@ -1191,7 +1192,7 @@ void Modify::add_compute(int narg, char **arg, int trysuffix) if (compute[ncompute] == NULL) { char str[128]; - sprintf(str,"Unknown compute style %s",arg[2]); + snprintf(str,128,"Unknown compute style %s",arg[2]); error->all(FLERR,str); } diff --git a/src/molecule.cpp b/src/molecule.cpp index dfbe3e1e08e07527096f6db6d4de80557c370415..454459084a70aceca4a09ad9b8972e2c1167a4a7 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -1632,7 +1632,7 @@ void Molecule::open(char *file) fp = fopen(file,"r"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open molecule file %s",file); + snprintf(str,128,"Cannot open molecule file %s",file); error->one(FLERR,str); } } diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 759f84e29f92406bace3bfb5ea5715be2f0c7e73..bc22fffc48fbe1d8bd0ebb9f49389b147a91256a 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1408,7 +1408,7 @@ void Neighbor::init_topology() void Neighbor::print_pairwise_info() { int i,m; - char str[128]; + char str[256]; NeighRequest *rq; FILE *out; diff --git a/src/pair_coul_streitz.cpp b/src/pair_coul_streitz.cpp index 1d725f4ca87c637ffb1e9855a126fe1e95f0cf41..920770ed7f83f8c16096a3d5e2a46614a24427e2 100644 --- a/src/pair_coul_streitz.cpp +++ b/src/pair_coul_streitz.cpp @@ -258,7 +258,7 @@ void PairCoulStreitz::read_file(char *file) fp = fopen(file,"r"); if (fp == NULL) { char str[128]; - sprintf(str,"Cannot open coul/streitz potential file %s",file); + snprintf(str,128,"Cannot open coul/streitz potential file %s",file); error->one(FLERR,str); } }