diff --git a/FEBio/FEBioApp.cpp b/FEBio/FEBioApp.cpp index f40b04639..5ebc026c6 100644 --- a/FEBio/FEBioApp.cpp +++ b/FEBio/FEBioApp.cpp @@ -259,7 +259,7 @@ bool FEBioApp::ParseCmdLine(int nargs, char* argv[]) { char szpath[1024] = { 0 }; febio::get_app_path(szpath, 1023); - sprintf(ops.szcnf, "%sfebio.xml", szpath); + snprintf(ops.szcnf, 1024, "%sfebio.xml", szpath); } // loop over the arguments @@ -337,7 +337,7 @@ bool FEBioApp::ParseCmdLine(int nargs, char* argv[]) if (szext == 0) { // we assume a default extension of .feb if none is provided - sprintf(ops.szfile, "%s.feb", argv[i]); + snprintf(ops.szfile, sizeof(ops.szfile), "%s.feb", argv[i]); } else strcpy(ops.szfile, argv[i]); ops.binteractive = false; @@ -448,7 +448,7 @@ bool FEBioApp::ParseCmdLine(int nargs, char* argv[]) if (szext == 0) { // we assume a default extension of .feb if none is provided - sprintf(ops.szfile, "%s.feb", sz); + snprintf(ops.szfile, sizeof(ops.szfile), "%s.feb", sz); } else { @@ -494,9 +494,9 @@ bool FEBioApp::ParseCmdLine(int nargs, char* argv[]) } else strcpy(szlogbase, szbase); - if (!blog) sprintf(ops.szlog, "%s.log", szlogbase); - if (!bplt) sprintf(ops.szplt, "%s.xplt", szbase); - if (!bdmp) sprintf(ops.szdmp, "%s.dmp", szbase); + if (!blog) snprintf(ops.szlog, sizeof(ops.szlog), "%s.log", szlogbase); + if (!bplt) snprintf(ops.szplt, sizeof(ops.szplt), "%s.xplt", szbase); + if (!bdmp) snprintf(ops.szdmp, sizeof(ops.szdmp), "%s.dmp", szbase); } else if (ops.szctrl[0]) { @@ -505,9 +505,9 @@ bool FEBioApp::ParseCmdLine(int nargs, char* argv[]) char* ch = strrchr(szbase, '.'); if (ch) *ch = 0; - if (!blog) sprintf(ops.szlog, "%s.log", szbase); - if (!bplt) sprintf(ops.szplt, "%s.xplt", szbase); - if (!bdmp) sprintf(ops.szdmp, "%s.dmp", szbase); + if (!blog) snprintf(ops.szlog, sizeof(ops.szlog), "%s.log", szbase); + if (!bplt) snprintf(ops.szplt, sizeof(ops.szplt), "%s.xplt", szbase); + if (!bdmp) snprintf(ops.szdmp, sizeof(ops.szdmp), "%s.dmp", szbase); } return brun; diff --git a/FEBio/FEBioCommand.cpp b/FEBio/FEBioCommand.cpp index 035e422fe..4ada016ed 100644 --- a/FEBio/FEBioCommand.cpp +++ b/FEBio/FEBioCommand.cpp @@ -305,7 +305,7 @@ int FEBioCmd_Config::run(int nargs, char* argv[]) } else if (nargs == 2) { - sprintf(ops.szcnf, "%s", argv[1]); + snprintf(ops.szcnf, sizeof(ops.szcnf), "%s", argv[1]); feApp->Configure(ops.szcnf); } else return invalid_nr_args(); @@ -510,7 +510,7 @@ int FEBioCmd_svg::run(int nargs, char **argv) strcpy(buf, szfile); char* ch = strrchr(buf, '.'); if (ch) *ch = 0; - sprintf(szsvg, "%s.svg", buf); + snprintf(szsvg, 1024, "%s.svg", buf); std::filebuf fb; fb.open(szsvg, std::ios::out); @@ -547,8 +547,8 @@ int FEBioCmd_out::run(int nargs, char **argv) strcpy(buf, szfile); char* ch = strrchr(buf, '.'); if (ch) *ch = 0; - sprintf(szK, "%s.out", buf); - sprintf(szR, "%s_rhs.out", buf); + snprintf(szK, 1024, "%s.out", buf); + snprintf(szR, 1024, "%s_rhs.out", buf); febio::write_hb(*A, szK, mode); febio::write_vector(R, szR, mode); diff --git a/FEBio/console.cpp b/FEBio/console.cpp index 76d9bb55e..cef74694d 100644 --- a/FEBio/console.cpp +++ b/FEBio/console.cpp @@ -93,7 +93,7 @@ void Console::SetTitle(const char* sz, ...) // make the message char sztitle[512]; va_start(args, sz); - vsprintf(sztitle, sz, args); + vsnprintf(sztitle, 512, sz, args); va_end(args); #ifdef WIN32 diff --git a/FEBio/febio_cb.cpp b/FEBio/febio_cb.cpp index 6a6197ec9..21ec8cf9c 100644 --- a/FEBio/febio_cb.cpp +++ b/FEBio/febio_cb.cpp @@ -74,9 +74,9 @@ bool update_console_cb(FEModel* pfem, unsigned int nwhen, void* pd) char szvers[64] = {0}; #ifndef NDEBUG - sprintf(szvers, "FEBio (DEBUG) %s", szver); + snprintf(szvers, 64, "FEBio (DEBUG) %s", szver); #else - sprintf(szvers, "FEBio %s", szver); + snprintf(szvers, 64, "FEBio %s", szver); #endif // print progress in title bar diff --git a/FEBioLib/FEBioModel.cpp b/FEBioLib/FEBioModel.cpp index c560f0835..3e872caf6 100644 --- a/FEBioLib/FEBioModel.cpp +++ b/FEBioLib/FEBioModel.cpp @@ -1388,7 +1388,7 @@ void FEBioModel::SerializeIOData(DumpStream &ar) // set the software string const char* szver = febio::getVersionString(); char szbuf[256] = { 0 }; - sprintf(szbuf, "FEBio %s", szver); + snprintf(szbuf, 256, "FEBio %s", szver); xplt->SetSoftwareString(szbuf); m_plot = xplt; @@ -1480,7 +1480,7 @@ bool FEBioModel::InitPlotFile() // set the software string const char* szver = febio::getVersionString(); char szbuf[256] = { 0 }; - sprintf(szbuf, "FEBio %s", szver); + snprintf(szbuf, 256, "FEBio %s", szver); xplt->SetSoftwareString(szbuf); m_plot = xplt; diff --git a/FEBioLib/LogStream.cpp b/FEBioLib/LogStream.cpp index 59779f777..7eea96ccc 100644 --- a/FEBioLib/LogStream.cpp +++ b/FEBioLib/LogStream.cpp @@ -39,7 +39,7 @@ void LogStream::printf(const char* sz, ...) // make the message char sztxt[1024] = { 0 }; va_start(args, sz); - vsprintf(sztxt, sz, args); + vsnprintf(sztxt, 1024, sz, args); va_end(args); print(sztxt); diff --git a/FEBioLib/Logfile.cpp b/FEBioLib/Logfile.cpp index 943b82adb..bd8888553 100644 --- a/FEBioLib/Logfile.cpp +++ b/FEBioLib/Logfile.cpp @@ -101,7 +101,7 @@ void Logfile::printf(const char* sz, ...) // make the message char sztxt[2048] = {0}; va_start(args, sz); - vsprintf(sztxt, sz, args); + vsnprintf(sztxt, 2048, sz, args); va_end(args); // print to file @@ -123,13 +123,13 @@ void Logfile::printbox(const char* sztitle, const char* sz, ...) // make the message char sztxt[1024] = {0}; va_start(args, sz); - vsprintf(sztxt, sz, args); + vsnprintf(sztxt, 1024, sz, args); va_end(args); // print the box char szmsg[1024] = {0}; char* ch = szmsg; - sprintf(szmsg,"\n *************************************************************************\n"); ch += strlen(ch); + snprintf(szmsg,1024, "\n *************************************************************************\n"); ch += strlen(ch); // print the title if (sztitle) { @@ -138,9 +138,9 @@ void Logfile::printbox(const char* sztitle, const char* sz, ...) char right[60] = {0}; strncpy(left, sztitle, l/2); strncpy(right, sztitle+l/2, l - l/2); - sprintf(ch," * %33s", left); ch += strlen(ch); - sprintf(ch,"%-36s *\n", right); ch += strlen(ch); -// sprintf(ch," *%71s*\n", ""); ch += strlen(ch); + snprintf(ch,1024, " * %33s", left); ch += strlen(ch); + snprintf(ch,1024, "%-36s *\n", right); ch += strlen(ch); +// snprintf(ch,1024, " *%71s*\n", ""); ch += strlen(ch); } // print the message @@ -162,13 +162,13 @@ void Logfile::printbox(const char* sztitle, const char* sz, ...) if (cn) *cn = '\n'; cn = ct + n; } - sprintf(ch," * %-69s *\n", ct); ch += strlen(ch); + snprintf(ch,1024," * %-69s *\n", ct); ch += strlen(ch); if (wrap) { ct[n] = tmp; } if (cn) ct = cn+1; } while (cn); // sprintf(ch," * *\n"); ch += strlen(ch); - sprintf(ch," *************************************************************************\n"); + snprintf(ch,1024," *************************************************************************\n"); // print the message printf(szmsg); diff --git a/FEBioLib/cmdoptions.cpp b/FEBioLib/cmdoptions.cpp index 7028249fe..b31f27019 100644 --- a/FEBioLib/cmdoptions.cpp +++ b/FEBioLib/cmdoptions.cpp @@ -90,7 +90,7 @@ bool febio::ProcessOptionsString(const std::string& s, CMDOPTIONS& ops) { char szpath[1024] = { 0 }; febio::get_app_path(szpath, 1023); - sprintf(ops.szcnf, "%sfebio.xml", szpath); + snprintf(ops.szcnf, 1024, "%sfebio.xml", szpath); } // loop over the arguments @@ -151,7 +151,7 @@ bool febio::ProcessOptionsString(const std::string& s, CMDOPTIONS& ops) if (szext == 0) { // we assume a default extension of .feb if none is provided - sprintf(ops.szfile, "%s.feb", sz); + snprintf(ops.szfile, 1024, "%s.feb", sz); } else strcpy(ops.szfile, sz); ops.binteractive = false; @@ -225,7 +225,7 @@ bool febio::ProcessOptionsString(const std::string& s, CMDOPTIONS& ops) if (szext == 0) { // we assume a default extension of .feb if none is provided - sprintf(ops.szfile, "%s.feb", sz); + snprintf(ops.szfile, sizeof(ops.szfile), "%s.feb", sz); } else { @@ -271,9 +271,9 @@ bool febio::ProcessOptionsString(const std::string& s, CMDOPTIONS& ops) } else strcpy(szlogbase, szbase); - if (!blog) sprintf(ops.szlog, "%s.log", szlogbase); - if (!bplt) sprintf(ops.szplt, "%s.xplt", szbase); - if (!bdmp) sprintf(ops.szdmp, "%s.dmp", szbase); + if (!blog) snprintf(ops.szlog, sizeof(ops.szlog), "%s.log", szlogbase); + if (!bplt) snprintf(ops.szplt, sizeof(ops.szplt), "%s.xplt", szbase); + if (!bdmp) snprintf(ops.szdmp, sizeof(ops.szdmp), "%s.dmp", szbase); } else if (ops.szctrl[0]) { @@ -282,9 +282,9 @@ bool febio::ProcessOptionsString(const std::string& s, CMDOPTIONS& ops) char* ch = strrchr(szbase, '.'); if (ch) *ch = 0; - if (!blog) sprintf(ops.szlog, "%s.log", szbase); - if (!bplt) sprintf(ops.szplt, "%s.xplt", szbase); - if (!bdmp) sprintf(ops.szdmp, "%s.dmp", szbase); + if (!blog) snprintf(ops.szlog, sizeof(ops.szlog), "%s.log", szbase); + if (!bplt) snprintf(ops.szplt, sizeof(ops.szplt), "%s.xplt", szbase); + if (!bdmp) snprintf(ops.szdmp, sizeof(ops.szdmp), "%s.dmp", szbase); } return true; diff --git a/FEBioLib/hello.cpp b/FEBioLib/hello.cpp index 471350af7..0f2ba2cea 100644 --- a/FEBioLib/hello.cpp +++ b/FEBioLib/hello.cpp @@ -36,7 +36,7 @@ int febio::Hello(LogStream& log) { char szversion[128] = { 0 }; char* szvernum = getVersionString(); - sprintf(szversion, " version %s\n", szvernum); + snprintf(szversion, 128, " version %s\n", szvernum); log.print("===========================================================================\n"); log.print(" ________ _________ _______ __ _________ \n"); @@ -62,4 +62,4 @@ int febio::Hello(LogStream& log) return 0; } - \ No newline at end of file + diff --git a/FEBioLib/input.cpp b/FEBioLib/input.cpp index 50048dc5e..48cb09222 100644 --- a/FEBioLib/input.cpp +++ b/FEBioLib/input.cpp @@ -54,7 +54,7 @@ void FEBioModel::print_parameter(FEParam& p, int level) { char sz[512] = {0}; int l = (int)strlen(p.name()) + 2*level; - sprintf(sz, "\t%*s %.*s", l, p.name(), 50-l, ".................................................."); + snprintf(sz, 512, "\t%*s %.*s", l, p.name(), 50-l, ".................................................."); if (p.dim() == 1) { switch (p.type()) diff --git a/FEBioLib/version.cpp b/FEBioLib/version.cpp index 5ff5c67df..aa46d4313 100644 --- a/FEBioLib/version.cpp +++ b/FEBioLib/version.cpp @@ -32,10 +32,10 @@ char* febio::getVersionString() static char version[32]; #ifndef DEVCOMMIT - sprintf(version, "%d.%d.%d", VERSION, SUBVERSION, SUBSUBVERSION); + snprintf(version, 32, "%d.%d.%d", VERSION, SUBVERSION, SUBSUBVERSION); #else - sprintf(version, "%d.%d.%d.%s", VERSION, SUBVERSION, SUBSUBVERSION, DEVCOMMIT); + snprintf(version, 32, "%d.%d.%d.%s", VERSION, SUBVERSION, SUBSUBVERSION, DEVCOMMIT); #endif return version; -} \ No newline at end of file +} diff --git a/FEBioOpt/FEOptimize.cpp b/FEBioOpt/FEOptimize.cpp index d37c0435e..10e57213e 100644 --- a/FEBioOpt/FEOptimize.cpp +++ b/FEBioOpt/FEOptimize.cpp @@ -47,7 +47,7 @@ FEOptimize::FEOptimize(FEModel* pfem) : FECoreTask(pfem), m_opt(pfem) bool FEOptimize::Init(const char* szfile) { char szversion[32] = { 0 }; - sprintf(szversion, "version %d.%d", VERSION, SUB_VERSION); + snprintf(szversion, 32, "version %d.%d", VERSION, SUB_VERSION); feLog("P A R A M E T E R O P T I M I Z A T I O N M O D U L E\n%s\n\n", szversion); // read the data from the xml input file diff --git a/FEBioXML/FEBioGeometrySection.cpp b/FEBioXML/FEBioGeometrySection.cpp index c54b22015..316abf38b 100644 --- a/FEBioXML/FEBioGeometrySection.cpp +++ b/FEBioXML/FEBioGeometrySection.cpp @@ -1043,7 +1043,7 @@ void FEBioGeometrySection25::ParsePartSection(XMLTag& tag) // redirect input to another file char xpath[256] = {0}; - sprintf(xpath, "febio_spec/Geometry/Part[@name=%s]", szname); + snprintf(xpath, 256, "febio_spec/Geometry/Part[@name=%s]", szname); XMLReader xml; if (xml.Open(szfrom) == false) throw XMLReader::InvalidAttributeValue(tag, "from", szfrom); XMLTag tag2; diff --git a/FEBioXML/FEBioGeometrySection3.cpp b/FEBioXML/FEBioGeometrySection3.cpp index 43028abcb..a1bbecbd4 100644 --- a/FEBioXML/FEBioGeometrySection3.cpp +++ b/FEBioXML/FEBioGeometrySection3.cpp @@ -103,7 +103,7 @@ void FEBioGeometrySection3::ParsePartSection(XMLTag& tag) // redirect input to another file char xpath[256] = {0}; - sprintf(xpath, "febio_spec/Geometry/Part[@name=%s]", szname); + snprintf(xpath, 256, "febio_spec/Geometry/Part[@name=%s]", szname); XMLReader xml; if (xml.Open(szfrom) == false) throw XMLReader::InvalidAttributeValue(tag, "from", szfrom); XMLTag tag2; diff --git a/FEBioXML/FEBioImport.cpp b/FEBioXML/FEBioImport.cpp index 95cc5ff87..abf87857f 100644 --- a/FEBioXML/FEBioImport.cpp +++ b/FEBioXML/FEBioImport.cpp @@ -457,7 +457,7 @@ bool FEBioImport::ReadFile(const char* szfile, bool broot) // find the section we are looking for char sz[512] = {0}; - sprintf(sz, "febio_spec/%s", tag.Name()); + snprintf(sz, 512, "febio_spec/%s", tag.Name()); if (xml2.FindTag(sz, tag2) == false) return errf("FATAL ERROR: Couldn't find %s section in file %s.\n\n", tag.Name(), szinc); // parse the section @@ -528,9 +528,9 @@ void FEBioImport::ParseVersion(XMLTag &tag) } //----------------------------------------------------------------------------- -void FEBioImport::SetDumpfileName(const char* sz) { sprintf(m_szdmp, "%s", sz); } -void FEBioImport::SetLogfileName (const char* sz) { sprintf(m_szlog, "%s", sz); } -void FEBioImport::SetPlotfileName(const char* sz) { sprintf(m_szplt, "%s", sz); } +void FEBioImport::SetDumpfileName(const char* sz) { snprintf(m_szdmp, sizeof(m_szdmp), "%s", sz); } +void FEBioImport::SetLogfileName (const char* sz) { snprintf(m_szlog, sizeof(m_szlog), "%s", sz); } +void FEBioImport::SetPlotfileName(const char* sz) { snprintf(m_szplt, sizeof(m_szplt), "%s", sz); } //----------------------------------------------------------------------------- void FEBioImport::AddDataRecord(DataRecord* pd) diff --git a/FEBioXML/FEBioIncludeSection.cpp b/FEBioXML/FEBioIncludeSection.cpp index b06272d43..093f0a1ad 100644 --- a/FEBioXML/FEBioIncludeSection.cpp +++ b/FEBioXML/FEBioIncludeSection.cpp @@ -42,7 +42,7 @@ void FEBioIncludeSection::Parse(XMLTag& tag) if (ch==0) { // pre-pend the name with the input path - sprintf(szin, "%s%s", GetFileReader()->GetFilePath(), tag.szvalue()); + snprintf(szin, 512, "%s%s", GetFileReader()->GetFilePath(), tag.szvalue()); } // read the file diff --git a/FEBioXML/FEBioOutputSection.cpp b/FEBioXML/FEBioOutputSection.cpp index d0cc92eb9..931d94d21 100644 --- a/FEBioXML/FEBioOutputSection.cpp +++ b/FEBioXML/FEBioOutputSection.cpp @@ -104,7 +104,7 @@ void FEBioOutputSection::ParseLogfile(XMLTag &tag) if(!FSPath::isPath(szlog)) { char szfile[1024] = {0}; - sprintf(szfile, "%s%s", szpath, szlog); + snprintf(szfile, 1024, "%s%s", szpath, szlog); GetFEBioImport()->SetLogfileName(szfile); } else @@ -126,7 +126,7 @@ void FEBioOutputSection::ParseLogfile(XMLTag &tag) // if we have a path, prepend the path's name if (szpath && szpath[0]) { - sprintf(szfilename, "%s%s", szpath, szfile); + snprintf(szfilename, 1024, "%s%s", szpath, szfile); } else strcpy(szfilename, szfile); szfile = szfilename; @@ -317,7 +317,7 @@ void FEBioOutputSection::ParsePlotfile(XMLTag &tag) const char* szpath = GetFileReader()->GetFilePath(); char szfile[1024] = {0}; - sprintf(szfile, "%s%s", szpath, szplt); + snprintf(szfile, 1024, "%s%s", szpath, szplt); GetFEBioImport()->SetPlotfileName(szfile); } else diff --git a/FEBioXML/FileImport.cpp b/FEBioXML/FileImport.cpp index bbdcd6a49..f4dd3ef6f 100644 --- a/FEBioXML/FileImport.cpp +++ b/FEBioXML/FileImport.cpp @@ -155,7 +155,7 @@ FEFileException::FEFileException(const char* sz, ...) // make the message va_start(args, sz); - vsprintf(m_szerr, sz, args); + vsnprintf(m_szerr, 2048, sz, args); va_end(args); } @@ -167,7 +167,7 @@ void FEFileException::SetErrorString(const char* sz, ...) // make the message va_start(args, sz); - vsprintf(m_szerr, sz, args); + vsnprintf(m_szerr, sizeof(m_szerr), sz, args); va_end(args); } @@ -1530,7 +1530,7 @@ bool FEFileImport::errf(const char* szerr, ...) // copy to string va_start(args, szerr); - vsprintf(m_szerr, szerr, args); + vsnprintf(m_szerr, sizeof(m_szerr), szerr, args); va_end(args); // close the file diff --git a/FECore/FEException.cpp b/FECore/FEException.cpp index 35a65e3ca..d8931a95a 100644 --- a/FECore/FEException.cpp +++ b/FECore/FEException.cpp @@ -59,7 +59,7 @@ void FEException::what(const char* msg, ...) // make the message char sztxt[1024] = { 0 }; va_start(args, msg); - vsprintf(sztxt, msg, args); + vsnprintf(sztxt, 1024, msg, args); va_end(args); m_what = sztxt; diff --git a/FECore/FEMathController.cpp b/FECore/FEMathController.cpp index 69545c269..bcb81766e 100644 --- a/FECore/FEMathController.cpp +++ b/FECore/FEMathController.cpp @@ -53,7 +53,7 @@ bool FEMathController::Init() m_param.push_back(param); - sprintf(sz, "var_%d", i); + snprintf(sz, 64, "var_%d", i); m_val.AddVariable(sz); } diff --git a/FECore/FEMathIntervalController.cpp b/FECore/FEMathIntervalController.cpp index 63ea6bbdc..bd3795b9e 100644 --- a/FECore/FEMathIntervalController.cpp +++ b/FECore/FEMathIntervalController.cpp @@ -61,7 +61,7 @@ bool FEMathIntervalController::Init() m_param.push_back(param); - sprintf(sz, "var_%d", i); + snprintf(sz, 64, "var_%d", i); m_val.AddVariable(sz); } diff --git a/FECore/FEModel.cpp b/FECore/FEModel.cpp index 80c059e4d..36ce4719d 100644 --- a/FECore/FEModel.cpp +++ b/FECore/FEModel.cpp @@ -1960,7 +1960,7 @@ void FEModel::Logf(int ntag, const char* msg, ...) // make the message char sztxt[2048] = { 0 }; va_start(args, msg); - vsprintf(sztxt, msg, args); + vsnprintf(sztxt, 2048, msg, args); va_end(args); Log(ntag, sztxt); diff --git a/FECore/FSPath.cpp b/FECore/FSPath.cpp index d82589a79..7a1f13ea8 100644 --- a/FECore/FSPath.cpp +++ b/FECore/FSPath.cpp @@ -61,7 +61,7 @@ void FSPath::filePath(char* filename, char* path) char sep = '/'; #endif - sprintf(path,"%s%c", name.substr(0,index).c_str(), sep); + snprintf(path, name.length(), "%s%c", name.substr(0,index).c_str(), sep); } diff --git a/FECore/Timer.cpp b/FECore/Timer.cpp index 0225ae46c..b407a44e3 100644 --- a/FECore/Timer.cpp +++ b/FECore/Timer.cpp @@ -113,14 +113,14 @@ void Timer::time_str(char* sz) { int nhour, nmin, nsec; GetTime(nhour, nmin, nsec); - sprintf(sz, "%d:%02d:%02d", nhour, nmin, nsec); + snprintf(sz, 64, "%d:%02d:%02d", nhour, nmin, nsec); } void Timer::time_str(double fsec, char* sz) { int nhour, nmin, nsec; GetTime(fsec, nhour, nmin, nsec); - sprintf(sz, "%d:%02d:%02d", nhour, nmin, nsec); + snprintf(sz, 64, "%d:%02d:%02d", nhour, nmin, nsec); } //============================================================================ diff --git a/FECore/fecore_debug.cpp b/FECore/fecore_debug.cpp index 2003c7ee5..70f34425e 100644 --- a/FECore/fecore_debug.cpp +++ b/FECore/fecore_debug.cpp @@ -123,7 +123,7 @@ void FECoreDebugger::Print(const char* szformat, ...) if (m_fp == nullptr) { char fileName[256] = { 0 }; - sprintf(fileName, "febio_%d.%d.%d_debug.log", FE_SDK_MAJOR_VERSION, FE_SDK_SUB_VERSION, FE_SDK_SUBSUB_VERSION); + snprintf(fileName, 256, "febio_%d.%d.%d_debug.log", FE_SDK_MAJOR_VERSION, FE_SDK_SUB_VERSION, FE_SDK_SUBSUB_VERSION); m_fp = fopen(fileName, "wt"); assert(m_fp); } diff --git a/FECore/log.cpp b/FECore/log.cpp index 81fad8a1a..16322075c 100644 --- a/FECore/log.cpp +++ b/FECore/log.cpp @@ -38,7 +38,7 @@ void write_log(FEModel* fem, int ntag, const char* szmsg, ...) // make the message char sztxt[2048] = { 0 }; va_start(args, szmsg); - vsprintf(sztxt, szmsg, args); + vsnprintf(sztxt, 2048, szmsg, args); va_end(args); fem->Log(ntag, sztxt); diff --git a/XML/XMLReader.cpp b/XML/XMLReader.cpp index a4635d185..faf4a04e2 100644 --- a/XML/XMLReader.cpp +++ b/XML/XMLReader.cpp @@ -515,7 +515,7 @@ string format_string(const char* sz, ...) // make the message char szbuf[512]; va_start(args, sz); - vsprintf(szbuf, sz, args); + vsnprintf(szbuf, 512, sz, args); va_end(args); return szbuf; @@ -1224,4 +1224,4 @@ const std::string& XMLReader::GetLastComment() } return m_comment; -} \ No newline at end of file +} diff --git a/XML/XMLWriter.cpp b/XML/XMLWriter.cpp index db2339ef7..36faa4ab6 100644 --- a/XML/XMLWriter.cpp +++ b/XML/XMLWriter.cpp @@ -275,7 +275,7 @@ void XMLWriter::inc_level() int l=0; for (int i=0; i\n", m_sztab); + snprintf(szformat, 256, "%s\n", m_sztab); *m_stream << m_sztab << "\n"; } diff --git a/XML/XMLWriter.h b/XML/XMLWriter.h index a7d138cf4..f470bad5d 100644 --- a/XML/XMLWriter.h +++ b/XML/XMLWriter.h @@ -136,10 +136,10 @@ class XMLWriter void add_leaf(const char* szn, const char* szv); void add_leaf(const char* szn, const std::string& s); - void add_leaf(const char* szn, int n){ char szv[256]; sprintf(szv, "%d" , n); write_leaf(szn, szv); } - void add_leaf(const char* szn, bool b){ char szv[256]; sprintf(szv, "%d" , b); write_leaf(szn, szv); } - void add_leaf(const char* szn, double g){ char szv[256]; sprintf(szv, "%lg", g); write_leaf(szn, szv); } - void add_leaf(const char* szn, float g){ char szv[256]; sprintf(szv, "%g" , g); write_leaf(szn, szv); } + void add_leaf(const char* szn, int n){ char szv[256]; snprintf(szv, 256, "%d" , n); write_leaf(szn, szv); } + void add_leaf(const char* szn, bool b){ char szv[256]; snprintf(szv, 256, "%d" , b); write_leaf(szn, szv); } + void add_leaf(const char* szn, double g){ char szv[256]; snprintf(szv, 256, "%lg", g); write_leaf(szn, szv); } + void add_leaf(const char* szn, float g){ char szv[256]; snprintf(szv, 256, "%g" , g); write_leaf(szn, szv); } void add_leaf(const char* szn, int *pi, int n); void add_leaf(const char* szn, float* pg, int n); void add_leaf(const char* szn, double* pg, int n);