diff --git a/CMakeLists.txt b/CMakeLists.txt index a8332143..07363e82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # - musrfit --- DKS ----------------------------------------------------------- cmake_minimum_required(VERSION 3.17) -project(musrfit VERSION 1.8.0 LANGUAGES C CXX) +project(musrfit VERSION 1.8.1 LANGUAGES C CXX) #--- musrfit specific options ------------------------------------------------- option(dks "build musrfit with DKS (GPU/MIC) support" ON) diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index 798f0a88..4235dc98 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -3863,7 +3863,7 @@ Bool_t PMsrHandler::FilterNumber(TString str, const Char_t *filter, Int_t offset Char_t *cstr, filterStr[32]; cstr = new Char_t[str.Sizeof()]; strncpy(cstr, str.Data(), str.Sizeof()); - sprintf(filterStr, "%s%%d", filter); + snprintf(filterStr, sizeof(filterStr), "%s%%d", filter); // get number if present found = sscanf(cstr, filterStr, &no_found); @@ -6974,7 +6974,7 @@ UInt_t PMsrHandler::LastSignificant(Double_t dval, UInt_t precLimit) char str[128]; - sprintf(str, "%lf", dval); + snprintf(str, sizeof(str), "%lf", dval); // find decimal point for (UInt_t i=0; isize() == 1){ tstr += TString("T="); - sprintf(sval, "%0.2lf", ddvec->at(0).first); + snprintf(sval, sizeof(sval), "%0.2lf", ddvec->at(0).first); tstr += TString(sval) + TString("K,"); } else { for(UInt_t i(0); isize(); ++i){ - sprintf(sval, "T%u=", i); + snprintf(sval, sizeof(sval), "T%u=", i); tstr += TString(sval); - sprintf(sval, "%0.2lf", ddvec->at(i).first); + snprintf(sval, sizeof(sval), "%0.2lf", ddvec->at(i).first); tstr += TString(sval) + TString("K,"); } } @@ -955,10 +955,10 @@ void PMusrCanvas::UpdateInfoPad() tstr += TString("??,"); } else { if (dval < 1.0e4) { // Gauss makes sense as a unit - sprintf(sval, "%0.2lf", dval); + snprintf(sval, sizeof(sval), "%0.2lf", dval); tstr += TString(sval) + TString("G,"); } else { // Tesla makes sense as a unit - sprintf(sval, "%0.2lf", dval/1.0e4); + snprintf(sval, sizeof(sval), "%0.2lf", dval/1.0e4); tstr += TString(sval) + TString("T,"); } } @@ -969,10 +969,10 @@ void PMusrCanvas::UpdateInfoPad() tstr += TString("??,"); } else { if (dval < 1.0e3) { // keV makes sense as a unit - sprintf(sval, "%0.2lf", dval); + snprintf(sval, sizeof(sval), "%0.2lf", dval); tstr += TString(sval) + TString("keV,"); } else { // MeV makes sense as a unit - sprintf(sval, "%0.2lf", dval/1.0e3); + snprintf(sval, sizeof(sval), "%0.2lf", dval/1.0e3); tstr += TString(sval) + TString("MeV,"); } } @@ -1581,13 +1581,13 @@ void PMusrCanvas::SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat) } if (fStartWithFourier) - sprintf(ext, "_%d_F", fPlotNumber); + snprintf(ext, sizeof(ext), "_%d_F", fPlotNumber); else - sprintf(ext, "_%d", fPlotNumber); + snprintf(ext, sizeof(ext), "_%d", fPlotNumber); str.Replace(idx, size, ext, strlen(ext)); idx += strlen(ext); size = strlen(ext); - sprintf(ext, ".%s", graphicsFormat); + snprintf(ext, sizeof(ext), ".%s", graphicsFormat); str.Replace(idx, size, ext, strlen(ext)); std::cout << std::endl << ">> SaveGraphicsAndQuit: " << str.Data() << std::endl; @@ -6546,7 +6546,7 @@ UInt_t PMusrCanvas::GetNeededAccuracy(PMsrParamStructure param) if (param.fStep == 0.0) { // check if fit parameter is a constant, i.e. step==0 char str[128]; - sprintf(str, "%lf", param.fValue); + snprintf(str, sizeof(str), "%lf", param.fValue); // find decimal point for (UInt_t i=0; icompressionTag == 1) // gzip - sprintf(cmd, "tar -zcf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[0].Data()); + snprintf(cmd, sizeof(cmd), "tar -zcf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[0].Data()); else // bzip2 - sprintf(cmd, "tar -jcf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[0].Data()); + snprintf(cmd, sizeof(cmd), "tar -jcf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[0].Data()); if (system(cmd) == -1) { std::cerr << "**ERROR** cmd: " << cmd << " failed." << std::endl; } @@ -833,19 +833,19 @@ Bool_t PRunDataHandler::ReadWriteFilesList() fln += TString(".tar"); for (UInt_t i=0; ioutPathFileName.size(); i++) { if (i==0) { - sprintf(cmd, "tar -cf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[i].Data()); + snprintf(cmd, sizeof(cmd), "tar -cf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[i].Data()); } else { - sprintf(cmd, "tar -rf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[i].Data()); + snprintf(cmd, sizeof(cmd), "tar -rf %s %s", fln.Data(), fAny2ManyInfo->outPathFileName[i].Data()); } if (system(cmd) == -1) { std::cerr << "**ERROR** cmd: " << cmd << " failed." << std::endl; } } if (fAny2ManyInfo->compressionTag == 1) { // gzip - sprintf(cmd, "gzip %s", fln.Data()); + snprintf(cmd, sizeof(cmd), "gzip %s", fln.Data()); fln += ".gz"; } else { - sprintf(cmd, "bzip2 -z %s", fln.Data()); + snprintf(cmd, sizeof(cmd), "bzip2 -z %s", fln.Data()); fln += ".bz2"; } if (system(cmd) == -1) { @@ -1642,7 +1642,7 @@ Bool_t PRunDataHandler::ReadRootFile() // get all the data Char_t histoName[32]; for (Int_t i=0; i(folder->FindObjectAny(histoName)); if (!histo) { std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName; @@ -1671,14 +1671,14 @@ Bool_t PRunDataHandler::ReadRootFile() histoData.clear(); } // check if any post pileup histos are present at all (this is not the case for LEM data 2006 and earlier) - sprintf(histoName, "hDecay%02d", POST_PILEUP_HISTO_OFFSET); + snprintf(histoName, sizeof(histoName), "hDecay%02d", POST_PILEUP_HISTO_OFFSET); if (!folder->FindObjectAny(histoName)) { std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **WARNING** Couldn't get histo " << histoName; std::cerr << std::endl << ">> most probably this is an old (2006 or earlier) LEM file without post pileup histos."; std::cerr << std::endl; } else { for (Int_t i=0; i(folder->FindObjectAny(histoName)); if (!histo) { std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName; @@ -4676,7 +4676,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln) return false; } size = dataSet->GetData()->size(); - sprintf(str, "hDecay%02d", static_cast(i)); + snprintf(str, sizeof(str), "hDecay%02d", static_cast(i)); histo = new TH1F(str, str, size+1, -0.5, static_cast(size)+0.5); for (UInt_t j=0; jSetBinContent(j+1, dataSet->GetData()->at(j)); @@ -4694,7 +4694,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln) return false; } size = dataSet->GetData()->size(); - sprintf(str, "hDecay%02d", static_cast(i)); + snprintf(str, sizeof(str), "hDecay%02d", static_cast(i)); histo = new TH1F(str, str, static_cast(size/fAny2ManyInfo->rebin)+1, -0.5, static_cast(size)/static_cast(fAny2ManyInfo->rebin)+0.5); dataCount = 0; for (UInt_t j=0; jData()); MUD_setDas(fd, dummy); MUD_setExperimenter(fd, dummy); - sprintf(info, "%lf+-%lf (K)", fData[0].GetTemperature(0), fData[0].GetTempError(0)); + snprintf(info, sizeof(info), "%lf+-%lf (K)", fData[0].GetTemperature(0), fData[0].GetTempError(0)); MUD_setTemperature(fd, info); - sprintf(info, "%lf", fData[0].GetField()); + snprintf(info, sizeof(info), "%lf", fData[0].GetField()); MUD_setField(fd, info); // generate the histograms @@ -6219,7 +6219,7 @@ TString PRunDataHandler::FileNameFromTemplate(TString &fileNameTemplate, Int_t r if (idx == str.Length()) { // 'r' only TString runStr(""); char fmt[128]; - sprintf(fmt , "%%0%dd", str.Length()); + snprintf(fmt, sizeof(fmt), "%%0%dd", str.Length()); runStr.Form(fmt, run); result += runStr; } else { // not only 'r' diff --git a/src/classes/PStartupHandler.cpp b/src/classes/PStartupHandler.cpp index eae02dd2..ff71296f 100644 --- a/src/classes/PStartupHandler.cpp +++ b/src/classes/PStartupHandler.cpp @@ -114,7 +114,7 @@ PStartupHandler::PStartupHandler() // check if the startup file is found under $HOME/.musrfit home = getenv("HOME"); if (home != nullptr) { - sprintf(startup_path_name, "%s/.musrfit/musrfit_startup.xml", home); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home); if (StartupFileExists(startup_path_name)) { fStartupFilePath = TString(startup_path_name); fStartupFileFound = true; @@ -125,7 +125,7 @@ PStartupHandler::PStartupHandler() // check if the MUSRFITPATH system variable is set pmusrpath = getenv("MUSRFITPATH"); if (pmusrpath != nullptr) { - sprintf(startup_path_name, "%s/musrfit_startup.xml", pmusrpath); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/musrfit_startup.xml", pmusrpath); if (StartupFileExists(startup_path_name)) { fStartupFilePath = TString(startup_path_name); fStartupFileFound = true; @@ -135,9 +135,9 @@ PStartupHandler::PStartupHandler() if (!fStartupFileFound) { // MUSRFITPATH not set or empty, will try $ROOTSYS/bin home = getenv("ROOTSYS"); if (home != nullptr) { - sprintf(musrpath, "%s/bin", home); + snprintf(musrpath, sizeof(musrpath), "%s/bin", home); std::cerr << std::endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << std::endl; - sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/musrfit_startup.xml", musrpath); if (StartupFileExists(startup_path_name)) { fStartupFilePath = TString(startup_path_name); fStartupFileFound = true; @@ -153,7 +153,7 @@ PStartupHandler::PStartupHandler() } else { home = getenv("HOME"); if (home != nullptr) { - sprintf(startup_path_name, "%s/.musrfit/musrfit_startup.xml", home); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home); if (StartupFileExists(startup_path_name)) { fStartupFilePath = TString(startup_path_name); fStartupFileFound = true; @@ -631,7 +631,7 @@ Bool_t PStartupHandler::WriteDefaultStartupFile() // first check that $HOME/.musrfit exists and if NOT create it struct stat info; - sprintf(startup_path_name, "%s/.musrfit", home); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit", home); if (!stat(startup_path_name, &info)) { if (!(info.st_mode & S_IFDIR)) return false; @@ -643,7 +643,7 @@ Bool_t PStartupHandler::WriteDefaultStartupFile() } // set path-name for musrfit_startup.xml - sprintf(startup_path_name, "%s/.musrfit/musrfit_startup.xml", home); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home); std::ofstream fout(startup_path_name, std::ofstream::out); if (!fout.is_open()) { diff --git a/src/classes/PTheory.cpp b/src/classes/PTheory.cpp index ca64bdcc..1cb03100 100644 --- a/src/classes/PTheory.cpp +++ b/src/classes/PTheory.cpp @@ -841,12 +841,12 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock) if (static_cast(tokens->GetEntries()) < fgTheoDataBase[idx].fNoOfParam + 1) return; // make tidy string - sprintf(substr, "%-10s", fgTheoDataBase[idx].fName.Data()); + snprintf(substr, sizeof(substr), "%-10s", fgTheoDataBase[idx].fName.Data()); tidy = TString(substr); for (Int_t j=1; jGetEntries(); j++) { ostr = dynamic_cast(tokens->At(j)); str = ostr->GetString(); - sprintf(substr, "%6s", str.Data()); + snprintf(substr, sizeof(substr), "%6s", str.Data()); tidy += TString(substr); } if (fgTheoDataBase[idx].fComment.Length() != 0) { @@ -913,7 +913,7 @@ void PTheory::MakeCleanAndTidyPolynom(UInt_t i, PMsrLines *fullTheoryBlock) for (Int_t j=1; j(tokens->At(j)); str = ostr->GetString(); - sprintf(substr, "%6s", str.Data()); + snprintf(substr, sizeof(substr), "%6s", str.Data()); tidy += TString(substr); } diff --git a/src/external/BMWtools/BMWStartupHandler.cpp b/src/external/BMWtools/BMWStartupHandler.cpp index 353e756c..3e184271 100644 --- a/src/external/BMWtools/BMWStartupHandler.cpp +++ b/src/external/BMWtools/BMWStartupHandler.cpp @@ -403,7 +403,7 @@ void BMWStartupHandler::CheckLists() << "BMWStartupHandler::CheckLists: Most probably this will go wrong and should therefore be fixed in the xml-file!" << std::endl; char eChar[5]; for(unsigned int i(0); iAddText(str); - sprintf(str, "Run Number: %10d", GetRunNumber()); + snprintf(str, sizeof(str), "Run Number: %10d", GetRunNumber()); text = pt->AddText(str); - sprintf(str, "Moderator HV: %10.2f kV", fModeratorHV); + snprintf(str, sizeof(str), "Moderator HV: %10.2f kV", fModeratorHV); text = pt->AddText(str); - sprintf(str, "Sample HV: %10.2f kV", fSampleHV); + snprintf(str, sizeof(str), "Sample HV: %10.2f kV", fSampleHV); text = pt->AddText(str); - sprintf(str, "Impl. Energy: %10.2f keV", fImpEnergy); + snprintf(str, sizeof(str), "Impl. Energy: %10.2f keV", fImpEnergy); text = pt->AddText(str); - sprintf(str, "Sample T: %10.2f K", fSampleTemperature); + snprintf(str, sizeof(str), "Sample T: %10.2f K", fSampleTemperature); text = pt->AddText(str); - sprintf(str, "Sample B: %10.2f G", fSampleBField); + snprintf(str, sizeof(str), "Sample B: %10.2f G", fSampleBField); text = pt->AddText(str); - sprintf(str, "Time Res.: %10.7f ns", fTimeResolution); + snprintf(str, sizeof(str), "Time Res.: %10.7f ns", fTimeResolution); text = pt->AddText(str); - sprintf(str, "N Channels: %10d", fNChannels); + snprintf(str, sizeof(str), "N Channels: %10d", fNChannels); text = pt->AddText(str); - sprintf(str, "N Histograms: %10d", fNHist); + snprintf(str, sizeof(str), "N Histograms: %10d", fNHist); text = pt->AddText(str); - sprintf(str, "Offset PPC Histograms: %10d", fOffsetPPCHistograms); + snprintf(str, sizeof(str), "Offset PPC Histograms: %10d", fOffsetPPCHistograms); text = pt->AddText(str); strcpy(str, "Cuts: "); strcat(str, cuts); @@ -393,7 +393,7 @@ void TLemRunHeader::DrawHeader() const { strcpy(str,"t0: "); for (Int_t i=0; iAddText(str); diff --git a/src/external/libCuba/src/common/Fork.c b/src/external/libCuba/src/common/Fork.c index 358cefdc..2e024a25 100644 --- a/src/external/libCuba/src/common/Fork.c +++ b/src/external/libCuba/src/common/Fork.c @@ -75,7 +75,7 @@ Extern void SUFFIX(cubafork)(Spin **pspin) } if( cubaverb_ ) { - sprintf(out, "using %d cores %d accelerators via " + snprintf(out, sizeof(out), "using %d cores %d accelerators via " #ifdef HAVE_SHMGET "shared memory", #else diff --git a/src/external/libCuba/src/common/Parallel.c b/src/external/libCuba/src/common/Parallel.c index 895862f3..0218e056 100644 --- a/src/external/libCuba/src/common/Parallel.c +++ b/src/external/libCuba/src/common/Parallel.c @@ -47,7 +47,7 @@ static inline void DoSampleParallel(This *t, number n, creal *x, real *f t->neval += n; if( VERBOSE > 2 ) { - sprintf(out, "sampling " NUMBER " points each on %d cores", + snprintf(out, sizeof(out), "sampling " NUMBER " points each on %d cores", pcores, ncores); Print(out); } diff --git a/src/external/libCuba/src/common/stddecl.h b/src/external/libCuba/src/common/stddecl.h index e5d046ff..18cea5c8 100644 --- a/src/external/libCuba/src/common/stddecl.h +++ b/src/external/libCuba/src/common/stddecl.h @@ -94,7 +94,7 @@ enum { uninitialized = 0x61627563 }; var = atoi(env); \ if( cubaverb_ ) { \ char out[64]; \ - sprintf(out, "env " name " = %d", (int)var); \ + snprintf(out, sizeof(out), "env " name " = %d", (int)var); \ Print(out); \ } \ } \ @@ -280,7 +280,7 @@ enum { signature = 0x41425543 }; } \ if( ini | statemsg ) { \ char s[512]; \ - sprintf(s, ini ? \ + snprintf(s, sizeof(s), ini ? \ "\nError restoring state from %s, starting from scratch." : \ "\nRestored state from %s.", (t)->statefile); \ Print(s); \ @@ -307,7 +307,7 @@ enum { signature = 0x41425543 }; } \ if( fail | statemsg ) { \ char s[512]; \ - sprintf(s, fail ? \ + snprintf(s, sizeof(s), fail ? \ "\nError saving state to %s." : \ "\nSaved state to %s.", (t)->statefile); \ Print(s); \ diff --git a/src/external/libCuba/src/divonne/Integrate.c b/src/external/libCuba/src/divonne/Integrate.c index 335aa57c..38cc0fad 100644 --- a/src/external/libCuba/src/divonne/Integrate.c +++ b/src/external/libCuba/src/divonne/Integrate.c @@ -36,7 +36,7 @@ static int Integrate(This *t, real *integral, real *error, real *prob) int fail; if( VERBOSE > 1 ) { - sprintf(out, "Divonne input parameters:\n" + snprintf(out, sizeof(out), "Divonne input parameters:\n" " ndim " COUNT "\n ncomp " COUNT "\n" ML_NOT(" nvec " NUMBER "\n") " epsrel " REAL "\n epsabs " REAL "\n" @@ -189,7 +189,7 @@ if( StateWriteTest(t) ) { \ WriteState(t); if( VERBOSE ) { - char *oe = out + sprintf(out, "\n" + char *oe = out + snprintf(out, sizeof(out), "\n" "Iteration " COUNT " (pass " COUNT "): " COUNT " regions\n" NUMBER7 " integrand evaluations so far,\n" NUMBER7 " in optimizing regions,\n" @@ -197,7 +197,7 @@ if( StateWriteTest(t) ) { \ state->iter, state->pass, t->nregions, t->neval, t->neval_opt, t->neval_cut); for( comp = 0; comp < t->ncomp; ++comp ) - oe += sprintf(oe, "\n[" COUNT "] " + oe += snprintf(oe, sizeof(out), "\n[" COUNT "] " REAL " +- " REAL, comp + 1, SHOW(integral[comp]), SHOW(error[comp])); Print(out); @@ -255,7 +255,7 @@ if( StateWriteTest(t) ) { \ SamplesAlloc(t, &t->samples[1]); if( VERBOSE ) { - sprintf(out, "\nMain integration on " COUNT + snprintf(out, sizeof(out), "\nMain integration on " COUNT " regions with " NUMBER " samples per region.", t->nregions, t->samples[1].neff); Print(out); @@ -325,7 +325,7 @@ refine: can_adjust = false; if( VERBOSE > 2 ) { - sprintf(out, "Sampling remaining " COUNT + snprintf(out, sizeof(out), "Sampling remaining " COUNT " regions with " NUMBER " points per region.", t->nregions, t->samples[1].neff); Print(out); @@ -369,7 +369,7 @@ refine: if( VERBOSE > 2 ) { cchar *msg = "\nRegion (" REALF ") - (" REALF ")"; for( B = (b = region->bounds) + t->ndim; b < B; ++b ) { - oe += sprintf(oe, msg, b->lower, b->upper); + oe += snprintf(oe, sizeof(out), msg, b->lower, b->upper); msg = "\n (" REALF ") - (" REALF ")"; } } @@ -408,12 +408,12 @@ refine: if( VERBOSE > 2 ) { #define Out2(f, r) SHOW((r)->avg), SHOW(res->spread/t->samples[f].neff), SHOW((r)->err) #define Out(f) Out2(f, &tot->phase[f]) - oe += sprintf(oe, "\n[" COUNT "] " + oe += snprintf(oe, sizeof(out), "\n[" COUNT "] " REAL " +- " REAL "(" REAL ")\n " REAL " +- " REAL "(" REAL ")", ++comp, Out(0), Out(1)); - if( todo == 3 ) oe += sprintf(oe, "\n " + if( todo == 3 ) oe += snprintf(oe, sizeof(out), "\n " REAL " +- " REAL "(" REAL ")", Out2(2, res)); - oe += sprintf(oe, " \tchisq " REAL, SHOW(chisq)); + oe += snprintf(oe, sizeof(out), " \tchisq " REAL, SHOW(chisq)); } tot->integral += avg; @@ -440,9 +440,9 @@ refine: } if( VERBOSE > 2 ) { - char *oe = out + sprintf(out, "\nTotals:"); + char *oe = out + snprintf(out, sizeof(out), "\nTotals:"); for( tot = state->totals, comp = 0; tot < Tot; ++tot, ++comp ) - oe += sprintf(oe, "\n[" COUNT "] " + oe += snprintf(oe, sizeof(out), "\n[" COUNT "] " REAL " +- " REAL " \tchisq " REAL " (" COUNT " df)", comp + 1, SHOW(integral[comp]), SHOW(error[comp]), SHOW(tot->chisq), df); diff --git a/src/external/libFitPofB/classes/TPofBCalc.cpp b/src/external/libFitPofB/classes/TPofBCalc.cpp index 8ac08893..eea231d2 100644 --- a/src/external/libFitPofB/classes/TPofBCalc.cpp +++ b/src/external/libFitPofB/classes/TPofBCalc.cpp @@ -317,7 +317,7 @@ void TPofBCalc::Calculate(const TBofZCalc *BofZ, const TTrimSPData *dataTrimSP, seconds = time (NULL); char debugfile[50]; - int n = sprintf (debugfile, "test_Bz_%ld_%f.dat", seconds, fBmin); + int n = snprintf (debugfile, sizeof(debugfile), "test_Bz_%ld_%f.dat", seconds, fBmin); if (n > 0) { ofstream of(debugfile); @@ -330,10 +330,10 @@ void TPofBCalc::Calculate(const TBofZCalc *BofZ, const TTrimSPData *dataTrimSP, } char debugfile1[50]; - int n1 = sprintf (debugfile1, "test_NZ_%ld_%f.dat", seconds, para[2]); + int n1 = snprintf (debugfile1, sizeof(debugfile1), "test_NZ_%ld_%f.dat", seconds, para[2]); char debugfile2[50]; - int n2 = sprintf (debugfile2, "test_NZgss_%ld_%f.dat", seconds, para[2]); + int n2 = snprintf (debugfile2, sizeof(debugfile2), "test_NZgss_%ld_%f.dat", seconds, para[2]); if (n1 > 0) { ofstream of1(debugfile1); diff --git a/src/external/libFitPofB/classes/TPofTCalc.cpp b/src/external/libFitPofB/classes/TPofTCalc.cpp index 2072ee00..12a1eb05 100644 --- a/src/external/libFitPofB/classes/TPofTCalc.cpp +++ b/src/external/libFitPofB/classes/TPofTCalc.cpp @@ -357,7 +357,7 @@ void TPofTCalc::FakeData(const string &rootOutputFileName, const std::vectorSetRunTitle("Fake Data"); if (optPar && (optPar->size() > 1)) { // set energy and field if they were specified runHeader->SetImpEnergy((*optPar)[1]); diff --git a/src/external/libPhotoMeissner/test/photo_meissner.cpp b/src/external/libPhotoMeissner/test/photo_meissner.cpp index f8a4a81d..af31e00b 100644 --- a/src/external/libPhotoMeissner/test/photo_meissner.cpp +++ b/src/external/libPhotoMeissner/test/photo_meissner.cpp @@ -163,7 +163,7 @@ int generateRgeFln(const string prefix, const string elist, vector &rgeF } ival = start; do { - sprintf(istr, "%d", ival); + snprintf(istr, sizeof(istr), "%d", ival); str = prefix + istr + ".rge"; rgeFln.push_back(str); ival += step; diff --git a/src/msr2msr.cpp b/src/msr2msr.cpp index 99b5ef02..81479015 100644 --- a/src/msr2msr.cpp +++ b/src/msr2msr.cpp @@ -78,8 +78,9 @@ void msr2msr_syntax() * - false otherwise * * \param str msr-file line + * \param size size of str */ -bool msr2msr_run(char *str) +bool msr2msr_run(char *str, const std::size_t size) { // not the RUN line itself, hence nothing to be done if (!strstr(str, "RUN")) @@ -109,27 +110,27 @@ bool msr2msr_run(char *str) } if (tokens->GetEntries() == 5) { // already a new msr file, do only add the proper run comment - sprintf(str, "%s (name beamline institute data-file-format)", line.Data()); + snprintf(str, size, "%s (name beamline institute data-file-format)", line.Data()); return true; } if (run.Contains("NEMU")) { ostr[0] = dynamic_cast(tokens->At(1)); // file name - sprintf(str, "RUN %s MUE4 PSI WKM (name beamline institute data-file-format)", ostr[0]->GetString().Data()); + snprintf(str, size, "RUN %s MUE4 PSI WKM (name beamline institute data-file-format)", ostr[0]->GetString().Data()); } else if (run.Contains("PSI")) { ostr[0] = dynamic_cast(tokens->At(1)); // file name ostr[1] = dynamic_cast(tokens->At(2)); // beamline - sprintf(str, "RUN %s %s PSI PSI-BIN (name beamline institute data-file-format)", + snprintf(str, size, "RUN %s %s PSI PSI-BIN (name beamline institute data-file-format)", ostr[0]->GetString().Data(), ostr[1]->GetString().Data()); } else if (run.Contains("TRIUMF")) { ostr[0] = dynamic_cast(tokens->At(1)); // file name ostr[1] = dynamic_cast(tokens->At(2)); // beamline - sprintf(str, "RUN %s %s TRIUMF MUD (name beamline institute data-file-format)", + snprintf(str, size, "RUN %s %s TRIUMF MUD (name beamline institute data-file-format)", ostr[0]->GetString().Data(), ostr[1]->GetString().Data()); } else if (run.Contains("RAL")) { ostr[0] = dynamic_cast(tokens->At(1)); // file name ostr[1] = dynamic_cast(tokens->At(2)); // beamline - sprintf(str, "RUN %s %s RAL NEXUS (name beamline institute data-file-format)", + snprintf(str, size, "RUN %s %s RAL NEXUS (name beamline institute data-file-format)", ostr[0]->GetString().Data(), ostr[1]->GetString().Data()); } @@ -175,7 +176,7 @@ bool msr2msr_param(char *str) for (unsigned int i=0; i<4; i++) ostr[i] = dynamic_cast(tokens->At(i)); // number - sprintf(sstr, "%10s", ostr[0]->GetString().Data()); + snprintf(sstr, sizeof(sstr), "%10s", ostr[0]->GetString().Data()); // name strcat(sstr, " "); strcat(sstr, ostr[1]->GetString().Data()); @@ -206,7 +207,7 @@ bool msr2msr_param(char *str) for (unsigned int i=0; i<6; i++) ostr[i] = dynamic_cast(tokens->At(i)); // number - sprintf(sstr, "%10s", ostr[0]->GetString().Data()); + snprintf(sstr, sizeof(sstr), "%10s", ostr[0]->GetString().Data()); // name strcat(sstr, " "); strcat(sstr, ostr[1]->GetString().Data()); @@ -480,7 +481,7 @@ void msr2msr_replace(char *str, int paramNo) memset(temp, 0, sizeof(temp)); - sprintf(no, "%d", paramNo); + snprintf(no, sizeof(no), "%d", paramNo); int j=0; for (unsigned int i=0; i(chisq/chisqred), chisqred); + snprintf(str, size, " chisq = %lf, NDF = %d, chisq/NDF = %lf", chisq, static_cast(chisq/chisqred), chisqred); } } @@ -691,10 +693,10 @@ int main(int argc, char *argv[]) success = msr2msr_theory(str, theoryTag, noOfAddionalParams); break; case MSR_TAG_RUN: - success = msr2msr_run(str); + success = msr2msr_run(str, sizeof(str)); break; case MSR_TAG_STATISTIC: - success = msr2msr_statistic(str); + success = msr2msr_statistic(str, sizeof(str)); break; default: break; @@ -709,7 +711,7 @@ int main(int argc, char *argv[]) // check if conversion seems to be OK if (!success) { - sprintf(str, "rm -rf %s", argv[2]); + snprintf(str, sizeof(str), "rm -rf %s", argv[2]); if (system(str) == -1) { std::cerr << "**ERROR** cmd: " << str << " failed." << std::endl; return 0; diff --git a/src/musredit_qt5/mupp/plotter/PMuppStartupHandler.cpp b/src/musredit_qt5/mupp/plotter/PMuppStartupHandler.cpp index 6ffd2d9f..09857c93 100644 --- a/src/musredit_qt5/mupp/plotter/PMuppStartupHandler.cpp +++ b/src/musredit_qt5/mupp/plotter/PMuppStartupHandler.cpp @@ -103,7 +103,7 @@ PMuppStartupHandler::PMuppStartupHandler() // check if the startup file is found under $HOME/.musrfit/mupp home = getenv("HOME"); if (home != 0) { - sprintf(startup_path_name, "%s/.musrfit/mupp/mupp_startup.xml", home); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/mupp/mupp_startup.xml", home); if (StartupFileExists(startup_path_name)) { fStartupFilePath = TString(startup_path_name); fStartupFileFound = true; diff --git a/src/musredit_qt5/mupp/var/include/PErrorHandler.hpp b/src/musredit_qt5/mupp/var/include/PErrorHandler.hpp index 7c127ed2..5ec8a7a0 100644 --- a/src/musredit_qt5/mupp/var/include/PErrorHandler.hpp +++ b/src/musredit_qt5/mupp/var/include/PErrorHandler.hpp @@ -62,7 +62,7 @@ namespace mupp Iterator line_start = get_pos(err_pos, line); const char *homeStr = getenv("HOME"); char fln[1024]; - sprintf(fln, "%s/.musrfit/mupp/mupp_err.log", homeStr); + snprintf(fln, sizeof(fln), "%s/.musrfit/mupp/mupp_err.log", homeStr); std::ofstream fout(fln, std::ofstream::app); if (err_pos != last) { fout << message << what << ':' << std::endl; diff --git a/src/musredit_qt6/mupp/plotter/PMuppStartupHandler.cpp b/src/musredit_qt6/mupp/plotter/PMuppStartupHandler.cpp index 6ffd2d9f..09857c93 100644 --- a/src/musredit_qt6/mupp/plotter/PMuppStartupHandler.cpp +++ b/src/musredit_qt6/mupp/plotter/PMuppStartupHandler.cpp @@ -103,7 +103,7 @@ PMuppStartupHandler::PMuppStartupHandler() // check if the startup file is found under $HOME/.musrfit/mupp home = getenv("HOME"); if (home != 0) { - sprintf(startup_path_name, "%s/.musrfit/mupp/mupp_startup.xml", home); + snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/mupp/mupp_startup.xml", home); if (StartupFileExists(startup_path_name)) { fStartupFilePath = TString(startup_path_name); fStartupFileFound = true; diff --git a/src/musredit_qt6/mupp/var/include/PErrorHandler.hpp b/src/musredit_qt6/mupp/var/include/PErrorHandler.hpp index 7c127ed2..5ec8a7a0 100644 --- a/src/musredit_qt6/mupp/var/include/PErrorHandler.hpp +++ b/src/musredit_qt6/mupp/var/include/PErrorHandler.hpp @@ -62,7 +62,7 @@ namespace mupp Iterator line_start = get_pos(err_pos, line); const char *homeStr = getenv("HOME"); char fln[1024]; - sprintf(fln, "%s/.musrfit/mupp/mupp_err.log", homeStr); + snprintf(fln, sizeof(fln), "%s/.musrfit/mupp/mupp_err.log", homeStr); std::ofstream fout(fln, std::ofstream::app); if (err_pos != last) { fout << message << what << ':' << std::endl; diff --git a/src/musrfit.cpp b/src/musrfit.cpp index 1cf74f33..a1cf948a 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -284,10 +284,10 @@ void musrfit_write_root(TFile &f, TString fln, PRunData *data, int runCounter) char name[128]; TString title = fln.Copy(); - sprintf(name, "_%d", runCounter); + snprintf(name, sizeof(name), "_%d", runCounter); title.ReplaceAll(".root", name); - sprintf(name, "c%d", runCounter); + snprintf(name, sizeof(name),"c%d", runCounter); TCanvas *c = new TCanvas(name, title.Data(), 10, 10, 800, 600); diff --git a/src/musrgui/PDumpOutputHandler.cpp b/src/musrgui/PDumpOutputHandler.cpp index f905f109..d59bb52d 100644 --- a/src/musrgui/PDumpOutputHandler.cpp +++ b/src/musrgui/PDumpOutputHandler.cpp @@ -85,7 +85,7 @@ PDumpOutputHandler::~PDumpOutputHandler() } if (fProc->isRunning()) { // try low level kill char cmd[128]; - sprintf(cmd, "kill -9 %ld", fProcPID); + snprintf(cmd, sizeof(cnd), "kill -9 %ld", fProcPID); system(cmd); } if (fProc) { diff --git a/src/musrgui/PFitOutputHandler.cpp b/src/musrgui/PFitOutputHandler.cpp index a0098493..6a10daa4 100644 --- a/src/musrgui/PFitOutputHandler.cpp +++ b/src/musrgui/PFitOutputHandler.cpp @@ -88,7 +88,7 @@ PFitOutputHandler::~PFitOutputHandler() } if (fProc->isRunning()) { // try low level kill char cmd[128]; - sprintf(cmd, "kill -9 %ld", fProcPID); + snprintf(cmd, sizeof(cmd), "kill -9 %ld", fProcPID); system(cmd); } if (fProc) { diff --git a/src/musrview.cpp b/src/musrview.cpp index afd2a2e6..91495c87 100644 --- a/src/musrview.cpp +++ b/src/musrview.cpp @@ -396,7 +396,7 @@ int main(int argc, char *argv[]) char canvasName[32]; for (unsigned int i=0; iGetListOfCanvases()->FindObject(canvasName) != nullptr) { canvasVector[i]->~PMusrCanvas(); } diff --git a/src/tests/dynKT_LF/dynKT_LF.cpp b/src/tests/dynKT_LF/dynKT_LF.cpp index b974873b..3810ecb0 100644 --- a/src/tests/dynKT_LF/dynKT_LF.cpp +++ b/src/tests/dynKT_LF/dynKT_LF.cpp @@ -168,9 +168,9 @@ int main(int argc, char *argv[]) char fln[128]; if (gaussian) - sprintf(fln, "dynKT_LF_w0_%1.1f_width%1.1f_nu%1.1f_N%d_G.dat", param[0], param[1], param[2], N); + snprintf(fln, sizeof(fln), "dynKT_LF_w0_%1.1f_width%1.1f_nu%1.1f_N%d_G.dat", param[0], param[1], param[2], N); else - sprintf(fln, "dynKT_LF_w0_%1.1f_width%1.1f_nu%1.1f_N%d_L.dat", param[0], param[1], param[2], N); + snprintf(fln, sizeof(fln), "dynKT_LF_w0_%1.1f_width%1.1f_nu%1.1f_N%d_L.dat", param[0], param[1], param[2], N); const double H = Tmax/N; diff --git a/src/tests/fourier/fourier.cpp b/src/tests/fourier/fourier.cpp index 07c28573..985a8ce3 100644 --- a/src/tests/fourier/fourier.cpp +++ b/src/tests/fourier/fourier.cpp @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) // get data histo char histoName[32]; // read first the data which are NOT post pileup corrected - sprintf(histoName, "hDecay%02d", histoNo); + snprintf(histoName, sizeof(histoName), "hDecay%02d", histoNo); TH1F *histo = dynamic_cast(folder->FindObjectAny(histoName)); if (!histo) { cout << endl << "PRunDataHandler::ReadRootFile: Couldn't get histo " << histoName; diff --git a/src/tests/skewedGaussianTest/fakeData.cpp b/src/tests/skewedGaussianTest/fakeData.cpp index fd40df20..de364317 100644 --- a/src/tests/skewedGaussianTest/fakeData.cpp +++ b/src/tests/skewedGaussianTest/fakeData.cpp @@ -5,8 +5,6 @@ Author: Andreas Suter e-mail: andreas.suter@psi.ch - $Id$ - ***************************************************************************/ /*************************************************************************** @@ -443,7 +441,7 @@ int main(int argc, char *argv[]) // create run info folder and content TFolder *runInfoFolder = new TFolder("RunInfo", "Run Info"); TLemRunHeader *runHeader = new TLemRunHeader(); - sprintf(str, "Fake Data generated from %s", pBFileName.Data()); + snprintf(str, sizeof(str), "Fake Data generated from %s", pBFileName.Data()); runHeader->SetRunTitle(str); Float_t fval = timeResolution; runHeader->SetTimeResolution(fval);