From 4aa37f936c22198476867927d4f5b0d936cb2b54 Mon Sep 17 00:00:00 2001 From: marian Date: Thu, 24 Mar 2011 11:58:44 +0000 Subject: [PATCH] Replacing sprintf with snprintf Coverity warnings --- TPC/AliTPCCalibSignal.cxx | 4 ++-- TPC/AliTPCClusterParam.cxx | 38 +++++++++++++++++++------------------- TPC/AliTPCcalibDB.cxx | 4 ++-- TPC/AliTPCcalibLaser.cxx | 8 ++++---- TPC/AliTPCcalibTracks.cxx | 4 ++-- TPC/AliTPCkalmanFit.cxx | 12 ++++++------ 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/TPC/AliTPCCalibSignal.cxx b/TPC/AliTPCCalibSignal.cxx index 90d5f1049b2..40ab3dd1bae 100644 --- a/TPC/AliTPCCalibSignal.cxx +++ b/TPC/AliTPCCalibSignal.cxx @@ -508,8 +508,8 @@ TH2S* AliTPCCalibSignal::GetHisto(Int_t sector, TObjArray *arr, /*FOLD00*/ // if we are forced and histogram doesn't yes exist create it Char_t name[255], title[255]; - sprintf(name,"hCalib%s%.2d",type,sector); - sprintf(title,"%s calibration histogram sector %.2d",type,sector); + snprintf(name,255,"hCalib%s%.2d",type,sector); + snprintf(title,255,"%s calibration histogram sector %.2d",type,sector); // new histogram with Q calib information. One value for each pad! TH2S* hist = new TH2S(name,title, diff --git a/TPC/AliTPCClusterParam.cxx b/TPC/AliTPCClusterParam.cxx index 71c8f76fb68..7713de1692b 100644 --- a/TPC/AliTPCClusterParam.cxx +++ b/TPC/AliTPCClusterParam.cxx @@ -444,7 +444,7 @@ void AliTPCClusterParam::FitResolQ(TTree * tree, Int_t dim, Int_t type, Float_t TString varVal; varVal="Resol:AngleM/sqrt(QMean):Zm/QMean"; char varVal0[100]; - sprintf(varVal0,"Resol:AngleM:Zm"); + snprintf(varVal0,100,"Resol:AngleM:Zm"); // TString varErr; varErr="Sigma:AngleS:Zs"; @@ -511,7 +511,7 @@ void AliTPCClusterParam::FitResolQPar(TTree * tree, Int_t dim, Int_t type, Float TString varVal; varVal="Resol:AngleM/sqrt(QMean):Zm/QMean"; char varVal0[100]; - sprintf(varVal0,"Resol:AngleM:Zm"); + snprintf(varVal0,100,"Resol:AngleM:Zm"); // TString varErr; varErr="Sigma:AngleS:Zs"; @@ -698,7 +698,7 @@ void AliTPCClusterParam::FitRMSQ(TTree * tree, Int_t dim, Int_t type, Float_t *p TString varVal; varVal="RMSm:AngleM/sqrt(QMean):Zm/QMean"; char varVal0[100]; - sprintf(varVal0,"RMSm:AngleM:Zm"); + snprintf(varVal0,100,"RMSm:AngleM:Zm"); // TString varErr; varErr="sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Zs"; @@ -1155,19 +1155,19 @@ void AliTPCClusterParam::Test(TTree * tree, const char *output){ char hcut1[300]; char hexp1[300]; // - sprintf(hname1,"Delta0 Dir %d Pad %d",idim,ipad); - sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); - sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1); + snprintf(hname1,300,"Delta0 Dir %d Pad %d",idim,ipad); + snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); + snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1); TH1F his1DRel0(hname1, hname1, 100,-0.2, 0.2); - sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); + snprintf(hname1,1000,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); tree->Draw(hexp1,hcut1,""); his1DRel0.Write(); // - sprintf(hname1,"Delta0Par Dir %d Pad %d",idim,ipad); - sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); - sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1); + snprintf(hname1,300,"Delta0Par Dir %d Pad %d",idim,ipad); + snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); + snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1); TH1F his1DRel0Par(hname1, hname1, 100,-0.2, 0.2); - sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); + snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); tree->Draw(hexp1,hcut1,""); his1DRel0Par.Write(); // @@ -1182,19 +1182,19 @@ void AliTPCClusterParam::Test(TTree * tree, const char *output){ char hcut1[300]; char hexp1[300]; // - sprintf(hname1,"2DDelta0 Dir %d Pad %d",idim,ipad); - sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); - sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1); + snprintf(hname1,300,"2DDelta0 Dir %d Pad %d",idim,ipad); + snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); + snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1); TProfile2D profDRel0(hname1, hname1, 6,0,250,6,0,1); - sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); + snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); tree->Draw(hexp1,hcut1,""); profDRel0.Write(); // - sprintf(hname1,"2DDelta0Par Dir %d Pad %d",idim,ipad); - sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); - sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1); + snprintf(hname1,300,"2DDelta0Par Dir %d Pad %d",idim,ipad); + snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad); + snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1); TProfile2D profDRel0Par(hname1, hname1,6,0,250,6,0,1); - sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); + snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad); tree->Draw(hexp1,hcut1,""); profDRel0Par.Write(); // diff --git a/TPC/AliTPCcalibDB.cxx b/TPC/AliTPCcalibDB.cxx index 8f2c053955b..ef394f8830d 100644 --- a/TPC/AliTPCcalibDB.cxx +++ b/TPC/AliTPCcalibDB.cxx @@ -294,7 +294,7 @@ AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath) AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun); if (!entry) { - sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath); + snprintf(chinfo,1000,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath); AliError(chinfo); return 0; } @@ -1927,7 +1927,7 @@ AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMapp TFile *fileMapping = new TFile(nameMappingFile, "read"); AliTPCmapper *mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping"); if (!mapping) { - sprintf(chinfo,"Failed to get mapping object from %s. ...\n", nameMappingFile); + snprintf(chinfo,1000,"Failed to get mapping object from %s. ...\n", nameMappingFile); AliError (chinfo); return 0; } diff --git a/TPC/AliTPCcalibLaser.cxx b/TPC/AliTPCcalibLaser.cxx index fb415f1b63a..42b3aed2c88 100644 --- a/TPC/AliTPCcalibLaser.cxx +++ b/TPC/AliTPCcalibLaser.cxx @@ -3135,7 +3135,7 @@ void AliTPCcalibLaser::DumpScanInfo(TTree * chain, const char * cutUser){ memcpy(smZ, chain->GetV1(), entries*sizeof(Double_t)); // // - sprintf(grnamefull,"Side_%d_Bundle_%d_Rod_%d_Beam_%d", + snprintf(grnamefull,1000,"Side_%d_Bundle_%d_Rod_%d_Beam_%d", ltrp->GetSide(), ltrp->GetBundle(), ltrp->GetRod(), ltrp->GetBeam()); // store data // phi @@ -3156,7 +3156,7 @@ void AliTPCcalibLaser::DumpScanInfo(TTree * chain, const char * cutUser){ pphi[0] = fp.GetParameter(0); // offset pphi[1] = fp.GetParameter(1); // slope pphi[2] = TMath::Sqrt(fp.GetChisquare()/(entries-2.)); // normalized chi2 - sprintf(grname,"phi_id%d",id); + snprintf(grname,1000,"phi_id%d",id); grphi->SetName(grname); grphi->SetTitle(grnamefull); grphi->GetXaxis()->SetTitle("b_{z} (T)"); grphi->GetYaxis()->SetTitle("#Delta r#phi (cm)"); @@ -3174,7 +3174,7 @@ void AliTPCcalibLaser::DumpScanInfo(TTree * chain, const char * cutUser){ pphiP[0] = fp.GetParameter(0); // offset pphiP[1] = fp.GetParameter(1); // slope pphiP[2] = TMath::Sqrt(fp.GetChisquare()/(entries-2.)); // normalized chi2 - sprintf(grname,"phiP_id%d",id); + snprintf(grname,1000,"phiP_id%d",id); grphiP->SetName(grname); grphiP->SetTitle(grnamefull); grphiP->GetXaxis()->SetTitle("b_{z} (T)"); grphiP->GetYaxis()->SetTitle("#Delta #phi (rad)"); @@ -3192,7 +3192,7 @@ void AliTPCcalibLaser::DumpScanInfo(TTree * chain, const char * cutUser){ pmZ[0] = fp.GetParameter(0); // offset pmZ[1] = fp.GetParameter(1); // slope pmZ[2] = TMath::Sqrt(fp.GetChisquare()/(entries-2.)); // normalized chi2 - sprintf(grname,"mZ_id%d",id); + snprintf(grname,1000,"mZ_id%d",id); grmZ->SetName(grname); grmZ->SetTitle(grnamefull); grmZ->GetXaxis()->SetTitle("b_{z} (T)"); grmZ->GetYaxis()->SetTitle("#Delta z (cm)"); diff --git a/TPC/AliTPCcalibTracks.cxx b/TPC/AliTPCcalibTracks.cxx index 700bfaef615..ad5f589047e 100644 --- a/TPC/AliTPCcalibTracks.cxx +++ b/TPC/AliTPCcalibTracks.cxx @@ -976,10 +976,10 @@ void AliTPCcalibTracks::MakeResPlotsQTree(Int_t minEntries, const char* pathName // these histograms are delta histograms for given direction, padSize, chargeBin, // angleBin and driftLengthBin // later on they will be fitted with a gausian, its sigma is the resoltuion... - sprintf(name,"%s, zCenter: %f, angleCenter: %f", hres->GetName(), zCenter, angleCenter); + snprintf(name,200,"%s, zCenter: %f, angleCenter: %f", hres->GetName(), zCenter, angleCenter); // TH1D * projectionRes = new TH1D(name, name, zAxisDelta->GetNbins(), zAxisDelta->GetXmin(), zAxisDelta->GetXmax()); projectionRes->SetNameTitle(name, name); - sprintf(name,"%s, zCenter: %f, angleCenter: %f", hrms->GetName(),zCenter,angleCenter); + snprintf(name,200,"%s, zCenter: %f, angleCenter: %f", hrms->GetName(),zCenter,angleCenter); // TH1D * projectionRms = new TH1D(name, name, zAxisDelta->GetNbins(), zAxisRms->GetXmin(), zAxisRms->GetXmax()); projectionRms->SetNameTitle(name, name); diff --git a/TPC/AliTPCkalmanFit.cxx b/TPC/AliTPCkalmanFit.cxx index 661d96ba7f1..3e88968c9b0 100644 --- a/TPC/AliTPCkalmanFit.cxx +++ b/TPC/AliTPCkalmanFit.cxx @@ -1007,7 +1007,7 @@ AliTPCkalmanFit * AliTPCkalmanFit::Test(Int_t ntracks){ if (ipar0+ipar1==0) continue; Double_t param = (gRandom->Rndm()-0.5)*0.5; // generate random parameters char tname[100]; - sprintf(tname,"tscalingR%d%dSide%d",ipar0,ipar1,iside); + snprintf(tname,100,"tscalingR%d%dSide%d",ipar0,ipar1,iside); transformation = new AliTPCTransformation(tname,AliTPCTransformation::BitsSide(iside),"TPCscalingRPol",0,0,1); transformation->SetParams(0,5*0.25,0,&fpar); kalmanFit0->AddCalibration(transformation); @@ -1296,20 +1296,20 @@ void AliTPCkalmanFit::MakeTreeTrans(TTreeSRedirector *debug, const char *treeNam AliTPCTransformation * transform = (AliTPCTransformation *)fCalibration->At(icalib); char tname[1000]; // - sprintf(tname,"dx%s=",transform->GetName()); + snprintf(tname,1000,"dx%s=",transform->GetName()); adx[icalib] =dxdydz(icalib,0); cstream<