replaced sprintf -> snprintf throughout.

This commit is contained in:
suter_a 2022-11-05 20:16:44 +01:00
parent 44aacfca50
commit f3414f687c
27 changed files with 120 additions and 120 deletions

View File

@ -1,7 +1,7 @@
# - musrfit # - musrfit
cmake_minimum_required(VERSION 3.17) 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 ------------------------------------------------- #--- musrfit specific options -------------------------------------------------
option(nexus "build optional NeXus support. Needed for ISIS" OFF) option(nexus "build optional NeXus support. Needed for ISIS" OFF)

View File

@ -3863,7 +3863,7 @@ Bool_t PMsrHandler::FilterNumber(TString str, const Char_t *filter, Int_t offset
Char_t *cstr, filterStr[32]; Char_t *cstr, filterStr[32];
cstr = new Char_t[str.Sizeof()]; cstr = new Char_t[str.Sizeof()];
strncpy(cstr, str.Data(), str.Sizeof()); strncpy(cstr, str.Data(), str.Sizeof());
sprintf(filterStr, "%s%%d", filter); snprintf(filterStr, sizeof(filterStr), "%s%%d", filter);
// get number if present // get number if present
found = sscanf(cstr, filterStr, &no_found); found = sscanf(cstr, filterStr, &no_found);
@ -6609,7 +6609,7 @@ UInt_t PMsrHandler::LastSignificant(Double_t dval, UInt_t precLimit)
char str[128]; char str[128];
sprintf(str, "%lf", dval); snprintf(str, sizeof(str), "%lf", dval);
// find decimal point // find decimal point
for (UInt_t i=0; i<strlen(str); i++) { for (UInt_t i=0; i<strlen(str); i++) {

View File

@ -543,7 +543,7 @@ void PMusrCanvas::UpdateParamTheoryPad()
for (UInt_t i=0; i<param.size(); i++) { for (UInt_t i=0; i<param.size(); i++) {
str = ""; str = "";
accuracy = GetNeededAccuracy(param[i]); accuracy = GetNeededAccuracy(param[i]);
sprintf(accStr, "%%.%dlf", accuracy); snprintf(accStr, sizeof(accStr), "%%.%dlf", accuracy);
// parameter no // parameter no
str += param[i].fNo; str += param[i].fNo;
if (param[i].fNo<10) if (param[i].fNo<10)
@ -556,9 +556,9 @@ void PMusrCanvas::UpdateParamTheoryPad()
str += " "; str += " ";
// parameter value // parameter value
if (round(param[i].fValue)-param[i].fValue==0) if (round(param[i].fValue)-param[i].fValue==0)
sprintf(cnum, "%.1lf", param[i].fValue); snprintf(cnum, sizeof(cnum), "%.1lf", param[i].fValue);
else else
sprintf(cnum, accStr, param[i].fValue); snprintf(cnum, sizeof(cnum), accStr, param[i].fValue);
str += cnum; str += cnum;
for (Int_t j=0; j<9-(Int_t)strlen(cnum); j++) // fill spaces for (Int_t j=0; j<9-(Int_t)strlen(cnum); j++) // fill spaces
str += " "; str += " ";
@ -572,22 +572,22 @@ void PMusrCanvas::UpdateParamTheoryPad()
if ((fabs(fabs(param[i].fStep) - param[i].fPosError) < 0.1*fabs(param[i].fStep)) && if ((fabs(fabs(param[i].fStep) - param[i].fPosError) < 0.1*fabs(param[i].fStep)) &&
(fabs(fabs(param[i].fStep) - param[i].fPosError) < 0.1*param[i].fPosError)) { (fabs(fabs(param[i].fStep) - param[i].fPosError) < 0.1*param[i].fPosError)) {
if (round(err)-err==0) if (round(err)-err==0)
sprintf(cnum, "%.1lf", err); snprintf(cnum, sizeof(cnum), "%.1lf", err);
else else
sprintf(cnum, accStr, err); snprintf(cnum, sizeof(cnum), accStr, err);
} else { } else {
sprintf(accStr, "%%.%dlf!!", accuracy); snprintf(accStr, sizeof(accStr), "%%.%dlf!!", accuracy);
if (round(err)-err==0) if (round(err)-err==0)
sprintf(cnum, "%.1lf!!", err); snprintf(cnum, sizeof(cnum), "%.1lf!!", err);
else else
sprintf(cnum, accStr, err); snprintf(cnum, sizeof(cnum), accStr, err);
} }
str += cnum; str += cnum;
} else { // minos was not used } else { // minos was not used
if (round(param[i].fStep)-param[i].fStep==0) if (round(param[i].fStep)-param[i].fStep==0)
sprintf(cnum, "%.1lf", param[i].fStep); snprintf(cnum, sizeof(cnum), "%.1lf", param[i].fStep);
else else
sprintf(cnum, accStr, param[i].fStep); snprintf(cnum, sizeof(cnum), accStr, param[i].fStep);
str += cnum; str += cnum;
} }
ypos = 0.98-i*yoffset; ypos = 0.98-i*yoffset;
@ -936,13 +936,13 @@ void PMusrCanvas::UpdateInfoPad()
tstr += TString("??,"); tstr += TString("??,");
} else if (ddvec->size() == 1){ } else if (ddvec->size() == 1){
tstr += TString("T="); 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,"); tstr += TString(sval) + TString("K,");
} else { } else {
for(UInt_t i(0); i<ddvec->size(); ++i){ for(UInt_t i(0); i<ddvec->size(); ++i){
sprintf(sval, "T%u=", i); snprintf(sval, sizeof(sval), "T%u=", i);
tstr += TString(sval); 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,"); tstr += TString(sval) + TString("K,");
} }
} }
@ -953,10 +953,10 @@ void PMusrCanvas::UpdateInfoPad()
tstr += TString("??,"); tstr += TString("??,");
} else { } else {
if (dval < 1.0e4) { // Gauss makes sense as a unit 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,"); tstr += TString(sval) + TString("G,");
} else { // Tesla makes sense as a unit } 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,"); tstr += TString(sval) + TString("T,");
} }
} }
@ -967,10 +967,10 @@ void PMusrCanvas::UpdateInfoPad()
tstr += TString("??,"); tstr += TString("??,");
} else { } else {
if (dval < 1.0e3) { // keV makes sense as a unit 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,"); tstr += TString(sval) + TString("keV,");
} else { // MeV makes sense as a unit } 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,"); tstr += TString(sval) + TString("MeV,");
} }
} }
@ -1579,13 +1579,13 @@ void PMusrCanvas::SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat)
} }
if (fStartWithFourier) if (fStartWithFourier)
sprintf(ext, "_%d_F", fPlotNumber); snprintf(ext, sizeof(ext), "_%d_F", fPlotNumber);
else else
sprintf(ext, "_%d", fPlotNumber); snprintf(ext, sizeof(ext), "_%d", fPlotNumber);
str.Replace(idx, size, ext, strlen(ext)); str.Replace(idx, size, ext, strlen(ext));
idx += strlen(ext); idx += strlen(ext);
size = strlen(ext); size = strlen(ext);
sprintf(ext, ".%s", graphicsFormat); snprintf(ext, sizeof(ext), ".%s", graphicsFormat);
str.Replace(idx, size, ext, strlen(ext)); str.Replace(idx, size, ext, strlen(ext));
std::cout << std::endl << ">> SaveGraphicsAndQuit: " << str.Data() << std::endl; std::cout << std::endl << ">> SaveGraphicsAndQuit: " << str.Data() << std::endl;
@ -6539,7 +6539,7 @@ UInt_t PMusrCanvas::GetNeededAccuracy(PMsrParamStructure param)
if (param.fStep == 0.0) { // check if fit parameter is a constant, i.e. step==0 if (param.fStep == 0.0) { // check if fit parameter is a constant, i.e. step==0
char str[128]; char str[128];
sprintf(str, "%lf", param.fValue); snprintf(str, sizeof(str), "%lf", param.fValue);
// find decimal point // find decimal point
for (UInt_t i=0; i<strlen(str); i++) { for (UInt_t i=0; i<strlen(str); i++) {

View File

@ -823,9 +823,9 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
else // bzip2 else // bzip2
fln += TString(".tar.bz2"); fln += TString(".tar.bz2");
if (fAny2ManyInfo->compressionTag == 1) // gzip if (fAny2ManyInfo->compressionTag == 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 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) { if (system(cmd) == -1) {
std::cerr << "**ERROR** cmd: " << cmd << " failed." << std::endl; std::cerr << "**ERROR** cmd: " << cmd << " failed." << std::endl;
} }
@ -833,19 +833,19 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
fln += TString(".tar"); fln += TString(".tar");
for (UInt_t i=0; i<fAny2ManyInfo->outPathFileName.size(); i++) { for (UInt_t i=0; i<fAny2ManyInfo->outPathFileName.size(); i++) {
if (i==0) { 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 { } 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) { if (system(cmd) == -1) {
std::cerr << "**ERROR** cmd: " << cmd << " failed." << std::endl; std::cerr << "**ERROR** cmd: " << cmd << " failed." << std::endl;
} }
} }
if (fAny2ManyInfo->compressionTag == 1) { // gzip if (fAny2ManyInfo->compressionTag == 1) { // gzip
sprintf(cmd, "gzip %s", fln.Data()); snprintf(cmd, sizeof(cmd), "gzip %s", fln.Data());
fln += ".gz"; fln += ".gz";
} else { } else {
sprintf(cmd, "bzip2 -z %s", fln.Data()); snprintf(cmd, sizeof(cmd), "bzip2 -z %s", fln.Data());
fln += ".bz2"; fln += ".bz2";
} }
if (system(cmd) == -1) { if (system(cmd) == -1) {
@ -1642,7 +1642,7 @@ Bool_t PRunDataHandler::ReadRootFile()
// get all the data // get all the data
Char_t histoName[32]; Char_t histoName[32];
for (Int_t i=0; i<noOfHistos; i++) { for (Int_t i=0; i<noOfHistos; i++) {
sprintf(histoName, "hDecay%02d", i); snprintf(histoName, sizeof(histoName), "hDecay%02d", i);
TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(histoName)); TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(histoName));
if (!histo) { if (!histo) {
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName; std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName;
@ -1671,14 +1671,14 @@ Bool_t PRunDataHandler::ReadRootFile()
histoData.clear(); histoData.clear();
} }
// check if any post pileup histos are present at all (this is not the case for LEM data 2006 and earlier) // 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)) { if (!folder->FindObjectAny(histoName)) {
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **WARNING** Couldn't get histo " << 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 << ">> most probably this is an old (2006 or earlier) LEM file without post pileup histos.";
std::cerr << std::endl; std::cerr << std::endl;
} else { } else {
for (Int_t i=0; i<noOfHistos; i++) { for (Int_t i=0; i<noOfHistos; i++) {
sprintf(histoName, "hDecay%02d", i+POST_PILEUP_HISTO_OFFSET); snprintf(histoName, sizeof(histoName), "hDecay%02d", i+POST_PILEUP_HISTO_OFFSET);
TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(histoName)); TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(histoName));
if (!histo) { if (!histo) {
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName; std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName;
@ -4676,7 +4676,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
return false; return false;
} }
size = dataSet->GetData()->size(); size = dataSet->GetData()->size();
sprintf(str, "hDecay%02d", static_cast<Int_t>(i)); snprintf(str, sizeof(str), "hDecay%02d", static_cast<Int_t>(i));
histo = new TH1F(str, str, size+1, -0.5, static_cast<Double_t>(size)+0.5); histo = new TH1F(str, str, size+1, -0.5, static_cast<Double_t>(size)+0.5);
for (UInt_t j=0; j<size; j++) { for (UInt_t j=0; j<size; j++) {
histo->SetBinContent(j+1, dataSet->GetData()->at(j)); histo->SetBinContent(j+1, dataSet->GetData()->at(j));
@ -4694,7 +4694,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
return false; return false;
} }
size = dataSet->GetData()->size(); size = dataSet->GetData()->size();
sprintf(str, "hDecay%02d", static_cast<Int_t>(i)); snprintf(str, sizeof(str), "hDecay%02d", static_cast<Int_t>(i));
histo = new TH1F(str, str, static_cast<UInt_t>(size/fAny2ManyInfo->rebin)+1, -0.5, static_cast<Double_t>(size)/static_cast<Double_t>(fAny2ManyInfo->rebin)+0.5); histo = new TH1F(str, str, static_cast<UInt_t>(size/fAny2ManyInfo->rebin)+1, -0.5, static_cast<Double_t>(size)/static_cast<Double_t>(fAny2ManyInfo->rebin)+0.5);
dataCount = 0; dataCount = 0;
for (UInt_t j=0; j<size; j++) { for (UInt_t j=0; j<size; j++) {
@ -5558,9 +5558,9 @@ Bool_t PRunDataHandler::WriteMudFile(TString fln)
MUD_setOrient(fd, (char *)fData[0].GetOrientation()->Data()); MUD_setOrient(fd, (char *)fData[0].GetOrientation()->Data());
MUD_setDas(fd, dummy); MUD_setDas(fd, dummy);
MUD_setExperimenter(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); MUD_setTemperature(fd, info);
sprintf(info, "%lf", fData[0].GetField()); snprintf(info, sizeof(info), "%lf", fData[0].GetField());
MUD_setField(fd, info); MUD_setField(fd, info);
// generate the histograms // generate the histograms
@ -6219,7 +6219,7 @@ TString PRunDataHandler::FileNameFromTemplate(TString &fileNameTemplate, Int_t r
if (idx == str.Length()) { // 'r' only if (idx == str.Length()) { // 'r' only
TString runStr(""); TString runStr("");
char fmt[128]; char fmt[128];
sprintf(fmt , "%%0%dd", str.Length()); snprintf(fmt, sizeof(fmt), "%%0%dd", str.Length());
runStr.Form(fmt, run); runStr.Form(fmt, run);
result += runStr; result += runStr;
} else { // not only 'r' } else { // not only 'r'

View File

@ -114,7 +114,7 @@ PStartupHandler::PStartupHandler()
// check if the startup file is found under $HOME/.musrfit // check if the startup file is found under $HOME/.musrfit
home = getenv("HOME"); home = getenv("HOME");
if (home != nullptr) { 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)) { if (StartupFileExists(startup_path_name)) {
fStartupFilePath = TString(startup_path_name); fStartupFilePath = TString(startup_path_name);
fStartupFileFound = true; fStartupFileFound = true;
@ -125,7 +125,7 @@ PStartupHandler::PStartupHandler()
// check if the MUSRFITPATH system variable is set // check if the MUSRFITPATH system variable is set
pmusrpath = getenv("MUSRFITPATH"); pmusrpath = getenv("MUSRFITPATH");
if (pmusrpath != nullptr) { 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)) { if (StartupFileExists(startup_path_name)) {
fStartupFilePath = TString(startup_path_name); fStartupFilePath = TString(startup_path_name);
fStartupFileFound = true; fStartupFileFound = true;
@ -135,9 +135,9 @@ PStartupHandler::PStartupHandler()
if (!fStartupFileFound) { // MUSRFITPATH not set or empty, will try $ROOTSYS/bin if (!fStartupFileFound) { // MUSRFITPATH not set or empty, will try $ROOTSYS/bin
home = getenv("ROOTSYS"); home = getenv("ROOTSYS");
if (home != nullptr) { 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; 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)) { if (StartupFileExists(startup_path_name)) {
fStartupFilePath = TString(startup_path_name); fStartupFilePath = TString(startup_path_name);
fStartupFileFound = true; fStartupFileFound = true;
@ -153,7 +153,7 @@ PStartupHandler::PStartupHandler()
} else { } else {
home = getenv("HOME"); home = getenv("HOME");
if (home != nullptr) { 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)) { if (StartupFileExists(startup_path_name)) {
fStartupFilePath = TString(startup_path_name); fStartupFilePath = TString(startup_path_name);
fStartupFileFound = true; fStartupFileFound = true;
@ -620,7 +620,7 @@ Bool_t PStartupHandler::WriteDefaultStartupFile()
// first check that $HOME/.musrfit exists and if NOT create it // first check that $HOME/.musrfit exists and if NOT create it
struct stat info; 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 (!stat(startup_path_name, &info)) {
if (!(info.st_mode & S_IFDIR)) if (!(info.st_mode & S_IFDIR))
return false; return false;
@ -632,7 +632,7 @@ Bool_t PStartupHandler::WriteDefaultStartupFile()
} }
// set path-name for musrfit_startup.xml // 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); std::ofstream fout(startup_path_name, std::ofstream::out);
if (!fout.is_open()) { if (!fout.is_open()) {

View File

@ -841,12 +841,12 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock)
if (static_cast<UInt_t>(tokens->GetEntries()) < fgTheoDataBase[idx].fNoOfParam + 1) if (static_cast<UInt_t>(tokens->GetEntries()) < fgTheoDataBase[idx].fNoOfParam + 1)
return; return;
// make tidy string // make tidy string
sprintf(substr, "%-10s", fgTheoDataBase[idx].fName.Data()); snprintf(substr, sizeof(substr), "%-10s", fgTheoDataBase[idx].fName.Data());
tidy = TString(substr); tidy = TString(substr);
for (Int_t j=1; j<tokens->GetEntries(); j++) { for (Int_t j=1; j<tokens->GetEntries(); j++) {
ostr = dynamic_cast<TObjString*>(tokens->At(j)); ostr = dynamic_cast<TObjString*>(tokens->At(j));
str = ostr->GetString(); str = ostr->GetString();
sprintf(substr, "%6s", str.Data()); snprintf(substr, sizeof(substr), "%6s", str.Data());
tidy += TString(substr); tidy += TString(substr);
} }
if (fgTheoDataBase[idx].fComment.Length() != 0) { if (fgTheoDataBase[idx].fComment.Length() != 0) {
@ -913,7 +913,7 @@ void PTheory::MakeCleanAndTidyPolynom(UInt_t i, PMsrLines *fullTheoryBlock)
for (Int_t j=1; j<max; j++) { for (Int_t j=1; j<max; j++) {
ostr = dynamic_cast<TObjString*>(tokens->At(j)); ostr = dynamic_cast<TObjString*>(tokens->At(j));
str = ostr->GetString(); str = ostr->GetString();
sprintf(substr, "%6s", str.Data()); snprintf(substr, sizeof(substr), "%6s", str.Data());
tidy += TString(substr); tidy += TString(substr);
} }

View File

@ -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; << "BMWStartupHandler::CheckLists: Most probably this will go wrong and should therefore be fixed in the xml-file!" << std::endl;
char eChar[5]; char eChar[5];
for(unsigned int i(0); i<fEnergyList.size(); i++) { for(unsigned int i(0); i<fEnergyList.size(); i++) {
sprintf(eChar, "%02.1f", fEnergyList[i]); snprintf(eChar, sizeof(eChar), "%02.1f", fEnergyList[i]);
fEnergyLabelList.push_back(std::string(eChar)); fEnergyLabelList.push_back(std::string(eChar));
} }
} }

View File

@ -91,7 +91,7 @@ void TLemRunHeader::SetStopTimeString(const Char_t *stop){
void TLemRunHeader::SetModeratorHV(Float_t modHV, Float_t error){ void TLemRunHeader::SetModeratorHV(Float_t modHV, Float_t error){
TString str; TString str;
char s[80]; char s[80];
sprintf(s, "05 Moderator HV: %8.2f(%5.2f)", modHV, error); snprintf(s, sizeof(s), "05 Moderator HV: %8.2f(%5.2f)", modHV, error);
str = s; str = s;
fModeratorHVString.SetString(str); fModeratorHVString.SetString(str);
fModeratorHV = modHV; fModeratorHV = modHV;
@ -101,7 +101,7 @@ void TLemRunHeader::SetModeratorHV(Float_t modHV, Float_t error){
void TLemRunHeader::SetSampleHV(Float_t value, Float_t error){ void TLemRunHeader::SetSampleHV(Float_t value, Float_t error){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"06 Sample HV: %8.2f(%5.2f)", value, error); snprintf(s, sizeof(s), "06 Sample HV: %8.2f(%5.2f)", value, error);
str = s; str = s;
fSampleHVString.SetString(str); fSampleHVString.SetString(str);
fSampleHV = value; fSampleHV = value;
@ -111,7 +111,7 @@ void TLemRunHeader::SetSampleHV(Float_t value, Float_t error){
void TLemRunHeader::SetImpEnergy(Float_t value){ void TLemRunHeader::SetImpEnergy(Float_t value){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"07 Impl. Energy: %8.2f", value); snprintf(s, sizeof(s), "07 Impl. Energy: %8.2f", value);
str = s; str = s;
fImpEnergyString.SetString(str); fImpEnergyString.SetString(str);
fImpEnergy = value; fImpEnergy = value;
@ -120,7 +120,7 @@ void TLemRunHeader::SetImpEnergy(Float_t value){
void TLemRunHeader::SetSampleTemperature(Float_t value, Float_t error){ void TLemRunHeader::SetSampleTemperature(Float_t value, Float_t error){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"08 Sample T: %8.2f(%5.2f)", value, error); snprintf(s, sizeof(s), "08 Sample T: %8.2f(%5.2f)", value, error);
str = s; str = s;
fSampleTemperatureString.SetString(str); fSampleTemperatureString.SetString(str);
fSampleTemperature = value; fSampleTemperature = value;
@ -130,7 +130,7 @@ void TLemRunHeader::SetSampleTemperature(Float_t value, Float_t error){
void TLemRunHeader::SetSampleBField(Float_t value, Float_t error){ void TLemRunHeader::SetSampleBField(Float_t value, Float_t error){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"09 Sample B: %8.2f(%5.2f)", value, error); snprintf(s, sizeof(s), "09 Sample B: %8.2f(%5.2f)", value, error);
str = s; str = s;
fSampleBFieldString.SetString(str); fSampleBFieldString.SetString(str);
fSampleBField = value; fSampleBField = value;
@ -140,7 +140,7 @@ void TLemRunHeader::SetSampleBField(Float_t value, Float_t error){
void TLemRunHeader::SetTimeResolution(Float_t value){ void TLemRunHeader::SetTimeResolution(Float_t value){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"10 Time Res.: %10.7f", value); snprintf(s, sizeof(s), "10 Time Res.: %10.7f", value);
str = s; str = s;
fTimeResolutionString.SetString(str); fTimeResolutionString.SetString(str);
fTimeResolution = value; fTimeResolution = value;
@ -149,7 +149,7 @@ void TLemRunHeader::SetTimeResolution(Float_t value){
void TLemRunHeader::SetNChannels(Int_t value){ void TLemRunHeader::SetNChannels(Int_t value){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"11 N Channels: %8d", value); snprintf(s, sizeof(s), "11 N Channels: %8d", value);
str = s; str = s;
fNChannelsString.SetString(str); fNChannelsString.SetString(str);
fNChannels = value; fNChannels = value;
@ -158,7 +158,7 @@ void TLemRunHeader::SetNChannels(Int_t value){
void TLemRunHeader::SetNHist(Int_t value){ void TLemRunHeader::SetNHist(Int_t value){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"12 N Histograms: %6d", value); snprintf(s, sizeof(s), "12 N Histograms: %6d", value);
str = s; str = s;
fNHistString.SetString(str); fNHistString.SetString(str);
fNHist = value; fNHist = value;
@ -168,7 +168,7 @@ void TLemRunHeader::SetNHist(Int_t value){
void TLemRunHeader::SetOffsetPPCHistograms(UInt_t value){ void TLemRunHeader::SetOffsetPPCHistograms(UInt_t value){
TString str; TString str;
char s[80]; char s[80];
sprintf(s,"13 Offset PPC Histograms: %6d", value); snprintf(s, sizeof(s), "13 Offset PPC Histograms: %6d", value);
str = s; str = s;
fOffsetPPCHistogramsString.SetString(str); fOffsetPPCHistogramsString.SetString(str);
fOffsetPPCHistograms = value; fOffsetPPCHistograms = value;
@ -364,25 +364,25 @@ void TLemRunHeader::DrawHeader() const {
strcpy(str, "Run Stop: "); strcpy(str, "Run Stop: ");
strcat(str, runStop); strcat(str, runStop);
text = pt->AddText(str); text = pt->AddText(str);
sprintf(str, "Run Number: %10d", GetRunNumber()); snprintf(str, sizeof(str), "Run Number: %10d", GetRunNumber());
text = pt->AddText(str); 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); 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); 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); 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); 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); 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); text = pt->AddText(str);
sprintf(str, "N Channels: %10d", fNChannels); snprintf(str, sizeof(str), "N Channels: %10d", fNChannels);
text = pt->AddText(str); text = pt->AddText(str);
sprintf(str, "N Histograms: %10d", fNHist); snprintf(str, sizeof(str), "N Histograms: %10d", fNHist);
text = pt->AddText(str); text = pt->AddText(str);
sprintf(str, "Offset PPC Histograms: %10d", fOffsetPPCHistograms); snprintf(str, sizeof(str), "Offset PPC Histograms: %10d", fOffsetPPCHistograms);
text = pt->AddText(str); text = pt->AddText(str);
strcpy(str, "Cuts: "); strcpy(str, "Cuts: ");
strcat(str, cuts); strcat(str, cuts);
@ -393,7 +393,7 @@ void TLemRunHeader::DrawHeader() const {
strcpy(str,"t0: "); strcpy(str,"t0: ");
for (Int_t i=0; i<fNHist; i++){ for (Int_t i=0; i<fNHist; i++){
sprintf(helpstr, " %7.2f ", fTimeZero[i]); snprintf(helpstr, sizeof(helpstr), " %7.2f ", fTimeZero[i]);
strcat(str, helpstr); strcat(str, helpstr);
} }
text = pt->AddText(str); text = pt->AddText(str);

View File

@ -75,7 +75,7 @@ Extern void SUFFIX(cubafork)(Spin **pspin)
} }
if( cubaverb_ ) { if( cubaverb_ ) {
sprintf(out, "using %d cores %d accelerators via " snprintf(out, sizeof(out), "using %d cores %d accelerators via "
#ifdef HAVE_SHMGET #ifdef HAVE_SHMGET
"shared memory", "shared memory",
#else #else

View File

@ -47,7 +47,7 @@ static inline void DoSampleParallel(This *t, number n, creal *x, real *f
t->neval += n; t->neval += n;
if( VERBOSE > 2 ) { 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); pcores, ncores);
Print(out); Print(out);
} }

View File

@ -94,7 +94,7 @@ enum { uninitialized = 0x61627563 };
var = atoi(env); \ var = atoi(env); \
if( cubaverb_ ) { \ if( cubaverb_ ) { \
char out[64]; \ char out[64]; \
sprintf(out, "env " name " = %d", (int)var); \ snprintf(out, sizeof(out), "env " name " = %d", (int)var); \
Print(out); \ Print(out); \
} \ } \
} \ } \
@ -280,7 +280,7 @@ enum { signature = 0x41425543 };
} \ } \
if( ini | statemsg ) { \ if( ini | statemsg ) { \
char s[512]; \ char s[512]; \
sprintf(s, ini ? \ snprintf(s, sizeof(s), ini ? \
"\nError restoring state from %s, starting from scratch." : \ "\nError restoring state from %s, starting from scratch." : \
"\nRestored state from %s.", (t)->statefile); \ "\nRestored state from %s.", (t)->statefile); \
Print(s); \ Print(s); \
@ -307,7 +307,7 @@ enum { signature = 0x41425543 };
} \ } \
if( fail | statemsg ) { \ if( fail | statemsg ) { \
char s[512]; \ char s[512]; \
sprintf(s, fail ? \ snprintf(s, sizeof(s), fail ? \
"\nError saving state to %s." : \ "\nError saving state to %s." : \
"\nSaved state to %s.", (t)->statefile); \ "\nSaved state to %s.", (t)->statefile); \
Print(s); \ Print(s); \

View File

@ -36,7 +36,7 @@ static int Integrate(This *t, real *integral, real *error, real *prob)
int fail; int fail;
if( VERBOSE > 1 ) { if( VERBOSE > 1 ) {
sprintf(out, "Divonne input parameters:\n" snprintf(out, sizeof(out), "Divonne input parameters:\n"
" ndim " COUNT "\n ncomp " COUNT "\n" " ndim " COUNT "\n ncomp " COUNT "\n"
ML_NOT(" nvec " NUMBER "\n") ML_NOT(" nvec " NUMBER "\n")
" epsrel " REAL "\n epsabs " REAL "\n" " epsrel " REAL "\n epsabs " REAL "\n"
@ -189,7 +189,7 @@ if( StateWriteTest(t) ) { \
WriteState(t); WriteState(t);
if( VERBOSE ) { if( VERBOSE ) {
char *oe = out + sprintf(out, "\n" char *oe = out + snprintf(out, sizeof(out), "\n"
"Iteration " COUNT " (pass " COUNT "): " COUNT " regions\n" "Iteration " COUNT " (pass " COUNT "): " COUNT " regions\n"
NUMBER7 " integrand evaluations so far,\n" NUMBER7 " integrand evaluations so far,\n"
NUMBER7 " in optimizing regions,\n" NUMBER7 " in optimizing regions,\n"
@ -197,7 +197,7 @@ if( StateWriteTest(t) ) { \
state->iter, state->pass, t->nregions, state->iter, state->pass, t->nregions,
t->neval, t->neval_opt, t->neval_cut); t->neval, t->neval_opt, t->neval_cut);
for( comp = 0; comp < t->ncomp; ++comp ) for( comp = 0; comp < t->ncomp; ++comp )
oe += sprintf(oe, "\n[" COUNT "] " oe += snprintf(oe, sizeof(out), "\n[" COUNT "] "
REAL " +- " REAL, REAL " +- " REAL,
comp + 1, SHOW(integral[comp]), SHOW(error[comp])); comp + 1, SHOW(integral[comp]), SHOW(error[comp]));
Print(out); Print(out);
@ -255,7 +255,7 @@ if( StateWriteTest(t) ) { \
SamplesAlloc(t, &t->samples[1]); SamplesAlloc(t, &t->samples[1]);
if( VERBOSE ) { if( VERBOSE ) {
sprintf(out, "\nMain integration on " COUNT snprintf(out, sizeof(out), "\nMain integration on " COUNT
" regions with " NUMBER " samples per region.", " regions with " NUMBER " samples per region.",
t->nregions, t->samples[1].neff); t->nregions, t->samples[1].neff);
Print(out); Print(out);
@ -325,7 +325,7 @@ refine:
can_adjust = false; can_adjust = false;
if( VERBOSE > 2 ) { if( VERBOSE > 2 ) {
sprintf(out, "Sampling remaining " COUNT snprintf(out, sizeof(out), "Sampling remaining " COUNT
" regions with " NUMBER " points per region.", " regions with " NUMBER " points per region.",
t->nregions, t->samples[1].neff); t->nregions, t->samples[1].neff);
Print(out); Print(out);
@ -369,7 +369,7 @@ refine:
if( VERBOSE > 2 ) { if( VERBOSE > 2 ) {
cchar *msg = "\nRegion (" REALF ") - (" REALF ")"; cchar *msg = "\nRegion (" REALF ") - (" REALF ")";
for( B = (b = region->bounds) + t->ndim; b < B; ++b ) { 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 ")"; msg = "\n (" REALF ") - (" REALF ")";
} }
} }
@ -408,12 +408,12 @@ refine:
if( VERBOSE > 2 ) { if( VERBOSE > 2 ) {
#define Out2(f, r) SHOW((r)->avg), SHOW(res->spread/t->samples[f].neff), SHOW((r)->err) #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]) #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 ")\n "
REAL " +- " REAL "(" REAL ")", ++comp, Out(0), Out(1)); 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)); 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; tot->integral += avg;
@ -440,9 +440,9 @@ refine:
} }
if( VERBOSE > 2 ) { 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 ) 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)", REAL " +- " REAL " \tchisq " REAL " (" COUNT " df)",
comp + 1, SHOW(integral[comp]), SHOW(error[comp]), comp + 1, SHOW(integral[comp]), SHOW(error[comp]),
SHOW(tot->chisq), df); SHOW(tot->chisq), df);

View File

@ -317,7 +317,7 @@ void TPofBCalc::Calculate(const TBofZCalc *BofZ, const TTrimSPData *dataTrimSP,
seconds = time (NULL); seconds = time (NULL);
char debugfile[50]; 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) { if (n > 0) {
ofstream of(debugfile); ofstream of(debugfile);
@ -330,10 +330,10 @@ void TPofBCalc::Calculate(const TBofZCalc *BofZ, const TTrimSPData *dataTrimSP,
} }
char debugfile1[50]; 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]; 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) { if (n1 > 0) {
ofstream of1(debugfile1); ofstream of1(debugfile1);

View File

@ -357,7 +357,7 @@ void TPofTCalc::FakeData(const string &rootOutputFileName, const std::vector<dou
// create run info folder and content // create run info folder and content
TFolder *runInfoFolder = new TFolder("RunInfo", "Run Info"); TFolder *runInfoFolder = new TFolder("RunInfo", "Run Info");
TLemRunHeader *runHeader = new TLemRunHeader(); 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("Fake Data"); runHeader->SetRunTitle("Fake Data");
if (optPar && (optPar->size() > 1)) { // set energy and field if they were specified if (optPar && (optPar->size() > 1)) { // set energy and field if they were specified
runHeader->SetImpEnergy((*optPar)[1]); runHeader->SetImpEnergy((*optPar)[1]);

View File

@ -163,7 +163,7 @@ int generateRgeFln(const string prefix, const string elist, vector<string> &rgeF
} }
ival = start; ival = start;
do { do {
sprintf(istr, "%d", ival); snprintf(istr, sizeof(istr), "%d", ival);
str = prefix + istr + ".rge"; str = prefix + istr + ".rge";
rgeFln.push_back(str); rgeFln.push_back(str);
ival += step; ival += step;

View File

@ -78,8 +78,9 @@ void msr2msr_syntax()
* - false otherwise * - false otherwise
* *
* \param str msr-file line * \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 // not the RUN line itself, hence nothing to be done
if (!strstr(str, "RUN")) 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 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; return true;
} }
if (run.Contains("NEMU")) { if (run.Contains("NEMU")) {
ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name ostr[0] = dynamic_cast<TObjString*>(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")) { } else if (run.Contains("PSI")) {
ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name
ostr[1] = dynamic_cast<TObjString*>(tokens->At(2)); // beamline ostr[1] = dynamic_cast<TObjString*>(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()); ostr[0]->GetString().Data(), ostr[1]->GetString().Data());
} else if (run.Contains("TRIUMF")) { } else if (run.Contains("TRIUMF")) {
ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name
ostr[1] = dynamic_cast<TObjString*>(tokens->At(2)); // beamline ostr[1] = dynamic_cast<TObjString*>(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()); ostr[0]->GetString().Data(), ostr[1]->GetString().Data());
} else if (run.Contains("RAL")) { } else if (run.Contains("RAL")) {
ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name ostr[0] = dynamic_cast<TObjString*>(tokens->At(1)); // file name
ostr[1] = dynamic_cast<TObjString*>(tokens->At(2)); // beamline ostr[1] = dynamic_cast<TObjString*>(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()); 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++) for (unsigned int i=0; i<4; i++)
ostr[i] = dynamic_cast<TObjString*>(tokens->At(i)); ostr[i] = dynamic_cast<TObjString*>(tokens->At(i));
// number // number
sprintf(sstr, "%10s", ostr[0]->GetString().Data()); snprintf(sstr, sizeof(sstr), "%10s", ostr[0]->GetString().Data());
// name // name
strcat(sstr, " "); strcat(sstr, " ");
strcat(sstr, ostr[1]->GetString().Data()); strcat(sstr, ostr[1]->GetString().Data());
@ -206,7 +207,7 @@ bool msr2msr_param(char *str)
for (unsigned int i=0; i<6; i++) for (unsigned int i=0; i<6; i++)
ostr[i] = dynamic_cast<TObjString*>(tokens->At(i)); ostr[i] = dynamic_cast<TObjString*>(tokens->At(i));
// number // number
sprintf(sstr, "%10s", ostr[0]->GetString().Data()); snprintf(sstr, sizeof(sstr), "%10s", ostr[0]->GetString().Data());
// name // name
strcat(sstr, " "); strcat(sstr, " ");
strcat(sstr, ostr[1]->GetString().Data()); strcat(sstr, ostr[1]->GetString().Data());
@ -480,7 +481,7 @@ void msr2msr_replace(char *str, int paramNo)
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
sprintf(no, "%d", paramNo); snprintf(no, sizeof(no), "%d", paramNo);
int j=0; int j=0;
for (unsigned int i=0; i<strlen(str); i++) { for (unsigned int i=0; i<strlen(str); i++) {
@ -573,7 +574,7 @@ bool msr2msr_finalize_theory(char *fln, int theoryTag, int noOfAddionalParams)
// cp __temp.msr fln // cp __temp.msr fln
sprintf(str, "cp __temp.msr %s", fln); snprintf(str, sizeof(str), "cp __temp.msr %s", fln);
if (system(str) == -1) { if (system(str) == -1) {
std::cerr << "**ERROR** cmd: " << str << " failed." << std::endl; std::cerr << "**ERROR** cmd: " << str << " failed." << std::endl;
return false; return false;
@ -598,8 +599,9 @@ bool msr2msr_finalize_theory(char *fln, int theoryTag, int noOfAddionalParams)
* - false otherwise * - false otherwise
* *
* \param str msr-file statistic block line * \param str msr-file statistic block line
* \param size size of str
*/ */
bool msr2msr_statistic(char *str) { bool msr2msr_statistic(char *str, const std::size_t size) {
bool success = true; bool success = true;
char *pstr; char *pstr;
@ -621,7 +623,7 @@ bool msr2msr_statistic(char *str) {
} }
} }
if (success) { if (success) {
sprintf(str, " chisq = %lf, NDF = %d, chisq/NDF = %lf", chisq, static_cast<int>(chisq/chisqred), chisqred); snprintf(str, size, " chisq = %lf, NDF = %d, chisq/NDF = %lf", chisq, static_cast<int>(chisq/chisqred), chisqred);
} }
} }
@ -691,10 +693,10 @@ int main(int argc, char *argv[])
success = msr2msr_theory(str, theoryTag, noOfAddionalParams); success = msr2msr_theory(str, theoryTag, noOfAddionalParams);
break; break;
case MSR_TAG_RUN: case MSR_TAG_RUN:
success = msr2msr_run(str); success = msr2msr_run(str, sizeof(str));
break; break;
case MSR_TAG_STATISTIC: case MSR_TAG_STATISTIC:
success = msr2msr_statistic(str); success = msr2msr_statistic(str, sizeof(str));
break; break;
default: default:
break; break;
@ -709,7 +711,7 @@ int main(int argc, char *argv[])
// check if conversion seems to be OK // check if conversion seems to be OK
if (!success) { if (!success) {
sprintf(str, "rm -rf %s", argv[2]); snprintf(str, sizeof(str), "rm -rf %s", argv[2]);
if (system(str) == -1) { if (system(str) == -1) {
std::cerr << "**ERROR** cmd: " << str << " failed." << std::endl; std::cerr << "**ERROR** cmd: " << str << " failed." << std::endl;
return 0; return 0;

View File

@ -103,7 +103,7 @@ PMuppStartupHandler::PMuppStartupHandler()
// check if the startup file is found under $HOME/.musrfit/mupp // check if the startup file is found under $HOME/.musrfit/mupp
home = getenv("HOME"); home = getenv("HOME");
if (home != 0) { 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)) { if (StartupFileExists(startup_path_name)) {
fStartupFilePath = TString(startup_path_name); fStartupFilePath = TString(startup_path_name);
fStartupFileFound = true; fStartupFileFound = true;

View File

@ -62,7 +62,7 @@ namespace mupp
Iterator line_start = get_pos(err_pos, line); Iterator line_start = get_pos(err_pos, line);
const char *homeStr = getenv("HOME"); const char *homeStr = getenv("HOME");
char fln[1024]; 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); std::ofstream fout(fln, std::ofstream::app);
if (err_pos != last) { if (err_pos != last) {
fout << message << what << ':' << std::endl; fout << message << what << ':' << std::endl;

View File

@ -103,7 +103,7 @@ PMuppStartupHandler::PMuppStartupHandler()
// check if the startup file is found under $HOME/.musrfit/mupp // check if the startup file is found under $HOME/.musrfit/mupp
home = getenv("HOME"); home = getenv("HOME");
if (home != 0) { 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)) { if (StartupFileExists(startup_path_name)) {
fStartupFilePath = TString(startup_path_name); fStartupFilePath = TString(startup_path_name);
fStartupFileFound = true; fStartupFileFound = true;

View File

@ -62,7 +62,7 @@ namespace mupp
Iterator line_start = get_pos(err_pos, line); Iterator line_start = get_pos(err_pos, line);
const char *homeStr = getenv("HOME"); const char *homeStr = getenv("HOME");
char fln[1024]; 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); std::ofstream fout(fln, std::ofstream::app);
if (err_pos != last) { if (err_pos != last) {
fout << message << what << ':' << std::endl; fout << message << what << ':' << std::endl;

View File

@ -283,10 +283,10 @@ void musrfit_write_root(TFile &f, TString fln, PRunData *data, int runCounter)
char name[128]; char name[128];
TString title = fln.Copy(); TString title = fln.Copy();
sprintf(name, "_%d", runCounter); snprintf(name, sizeof(name), "_%d", runCounter);
title.ReplaceAll(".root", name); 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); TCanvas *c = new TCanvas(name, title.Data(), 10, 10, 800, 600);

View File

@ -85,7 +85,7 @@ PDumpOutputHandler::~PDumpOutputHandler()
} }
if (fProc->isRunning()) { // try low level kill if (fProc->isRunning()) { // try low level kill
char cmd[128]; char cmd[128];
sprintf(cmd, "kill -9 %ld", fProcPID); snprintf(cmd, sizeof(cnd), "kill -9 %ld", fProcPID);
system(cmd); system(cmd);
} }
if (fProc) { if (fProc) {

View File

@ -88,7 +88,7 @@ PFitOutputHandler::~PFitOutputHandler()
} }
if (fProc->isRunning()) { // try low level kill if (fProc->isRunning()) { // try low level kill
char cmd[128]; char cmd[128];
sprintf(cmd, "kill -9 %ld", fProcPID); snprintf(cmd, sizeof(cmd), "kill -9 %ld", fProcPID);
system(cmd); system(cmd);
} }
if (fProc) { if (fProc) {

View File

@ -396,7 +396,7 @@ int main(int argc, char *argv[])
char canvasName[32]; char canvasName[32];
for (unsigned int i=0; i<canvasVector.size(); i++) { for (unsigned int i=0; i<canvasVector.size(); i++) {
// check if canvas is still there before calling the destructor **TO BE DONE** // check if canvas is still there before calling the destructor **TO BE DONE**
sprintf(canvasName, "fMainCanvas%d", i); snprintf(canvasName, sizeof(canvasName), "fMainCanvas%d", i);
if (gROOT->GetListOfCanvases()->FindObject(canvasName) != nullptr) { if (gROOT->GetListOfCanvases()->FindObject(canvasName) != nullptr) {
canvasVector[i]->~PMusrCanvas(); canvasVector[i]->~PMusrCanvas();
} }

View File

@ -168,9 +168,9 @@ int main(int argc, char *argv[])
char fln[128]; char fln[128];
if (gaussian) 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 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; const double H = Tmax/N;

View File

@ -124,7 +124,7 @@ int main(int argc, char *argv[])
// get data histo // get data histo
char histoName[32]; char histoName[32];
// read first the data which are NOT post pileup corrected // 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<TH1F*>(folder->FindObjectAny(histoName)); TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(histoName));
if (!histo) { if (!histo) {
cout << endl << "PRunDataHandler::ReadRootFile: Couldn't get histo " << histoName; cout << endl << "PRunDataHandler::ReadRootFile: Couldn't get histo " << histoName;

View File

@ -5,8 +5,6 @@
Author: Andreas Suter Author: Andreas Suter
e-mail: andreas.suter@psi.ch e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
@ -443,7 +441,7 @@ int main(int argc, char *argv[])
// create run info folder and content // create run info folder and content
TFolder *runInfoFolder = new TFolder("RunInfo", "Run Info"); TFolder *runInfoFolder = new TFolder("RunInfo", "Run Info");
TLemRunHeader *runHeader = new TLemRunHeader(); 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); runHeader->SetRunTitle(str);
Float_t fval = timeResolution; Float_t fval = timeResolution;
runHeader->SetTimeResolution(fval); runHeader->SetTimeResolution(fval);