Making code secure - sprintf replaced with snprintf.
authorkowal2 <kowal2@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 28 Feb 2011 12:13:52 +0000 (12:13 +0000)
committerkowal2 <kowal2@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 28 Feb 2011 12:13:52 +0000 (12:13 +0000)
TPC/AliSimDigits.cxx
TPC/AliTPC.cxx
TPC/AliTPCAlign.cxx
TPC/AliTPCDigitizer.cxx
TPC/AliTPCPRF2D.cxx
TPC/AliTPCRF1D.cxx
TPC/AliTPCv2.cxx

index 3257e95..0dc796d 100644 (file)
@@ -372,7 +372,8 @@ AliH2F *  AliSimDigits::DrawTracks( const char *option,Int_t level,
   //  
   //make digits histo 
   char ch[30];
-  sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
+  //sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
+  snprintf(ch,30,"Track Segment_%d level %d ",GetID(),level );
   if ( (fNrows<1)|| (fNcols<1)) {
     return 0;
   }
index 0bebf6e..ed24ff8 100644 (file)
@@ -1240,8 +1240,9 @@ void AliTPC::SetDefaults(){
   // Use gamma 4
   //
   char  strgamma4[1000];
-  sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
+  //sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
   
+  snprintf(strgamma4,1000,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
   TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
   AliTPCRF1D     * rf    = new AliTPCRF1D(kTRUE,1000);
   rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
@@ -2317,7 +2318,8 @@ void AliTPC::MakeBranch(Option_t *option)
   AliDebug(1,"");
   if (fHitType<2) return;
   char branchname[10];
-  sprintf(branchname,"%s2",GetName());  
+  //sprintf(branchname,"%s2",GetName()); 
+  snprintf(branchname,10,"%s2",GetName()); 
   //
   // Get the pointer to the header
   const char *cH = strstr(option,"H");
@@ -2354,7 +2356,8 @@ void AliTPC::SetTreeAddress2()
   
   TBranch *branch;
   char branchname[20];
-  sprintf(branchname,"%s2",GetName());
+  //sprintf(branchname,"%s2",GetName());
+  snprintf(branchname,20,"%s2",GetName());
   //
   // Branch address for hit tree
   TTree *treeH = fLoader->TreeH();
@@ -2566,7 +2569,8 @@ AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
 // and one has to decide where to store the TPC parameters
 // M.Kowalski
   char paramName[50];
-  sprintf(paramName,"75x40_100x60_150x60");
+  //sprintf(paramName,"75x40_100x60_150x60");
+  snprintf(paramName,50,"75x40_100x60_150x60");
   AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
   if (paramTPC) {
     AliDebugClass(1,Form("TPC parameters %s found.",paramName));
index 8432c89..629738e 100644 (file)
@@ -82,10 +82,13 @@ AliTPCAlign::AliTPCAlign(Int_t reportloc, Int_t reportglob) :
   fFileLoc = new Char_t[80];
   fFileGlob = new Char_t[80];
   Char_t path[50];
-  sprintf(path,gSystem->Getenv("ALICE_ROOT")); 
+  //sprintf(path,gSystem->Getenv("ALICE_ROOT")); 
+  snprintf(path,50,gSystem->Getenv("ALICE_ROOT"));
   //
-  sprintf(fFileLoc,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
-  sprintf(fFileGlob,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
+  //sprintf(fFileLoc,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
+  snprintf(fFileLoc,100,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
+  //sprintf(fFileGlob,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
+  snprintf(fFileGlob,100,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
   //
 
 }
index 2ff41a1..b64e1f7 100644 (file)
@@ -132,15 +132,18 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   AliTPC *pTPC  = (AliTPC *) gAlice->GetModule("TPC");
   AliTPCParam * param = pTPC->GetParam();
   
-  sprintf(s,param->GetTitle());
-  sprintf(ss,"75x40_100x60");
+  //sprintf(s,param->GetTitle());
+  snprintf(s,100,param->GetTitle());
+  //sprintf(ss,"75x40_100x60");
+  snprintf(ss,100,"75x40_100x60");
   if(strcmp(s,ss)==0){
     printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
     delete param;
     param=new AliTPCParamSR();
   }
   else{
-   sprintf(ss,"75x40_100x60_150x60");
+    //sprintf(ss,"75x40_100x60_150x60");
+    snprintf(ss,100,"75x40_100x60_150x60");
    if(strcmp(s,ss)!=0) {
      printf("No TPC parameters found...\n");
      exit(2); 
@@ -200,7 +203,8 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
         return;
        }
 
-      sprintf(phname,"lhcphase%d",i1);
+      //sprintf(phname,"lhcphase%d",i1);
+      snprintf(phname,100,"lhcphase%d",i1);
       TParameter<float> *ph = (TParameter<float>*)treear->GetUserInfo()
                               ->FindObject("lhcphase0");
       if(!ph){
index 5eb88ea..5bd05fb 100644 (file)
@@ -282,7 +282,8 @@ void AliTPCPRF2D::SetParam( TF2 *const GRF,  Float_t kNorm,
    if (fGRF !=0 ) fGRF->Delete();
    fGRF = GRF;
    fKNorm = kNorm;
-   sprintf(fType,"User");
+   //sprintf(fType,"User");
+   snprintf(fType,6,"User");
    if (sigmaX ==0) sigmaX=(fWidth*(1+TMath::Abs(fK)))/fgkSQRT12;
    if (sigmaY ==0) sigmaY=(fWidth*(1+TMath::Abs(fK)))/fgkSQRT12;
    fOrigSigmaX=sigmaX; 
@@ -312,7 +313,8 @@ void AliTPCPRF2D::SetGauss(Float_t sigmaX, Float_t sigmaY,
   fKNorm = kNorm;
   fOrigSigmaX=sigmaX;
   fOrigSigmaY=sigmaY;
-  sprintf(fType,"Gauss");
+  //sprintf(fType,"Gauss");
+  snprintf(fType,6,"Gauss");
   if (fGRF !=0 ) fGRF->Delete();
   fGRF = new TF2("FunGauss2D",FunGauss2D,-5.,5.,-5.,5.,4);
   
@@ -345,7 +347,8 @@ void AliTPCPRF2D::SetCosh(Float_t sigmaX, Float_t sigmaY,
   fKNorm = kNorm;
   fOrigSigmaX=sigmaX;
   fOrigSigmaY=sigmaY; 
-  sprintf(fType,"Cosh");
+  //  sprintf(fType,"Cosh");
+  snprintf(fType,6,"Cosh");
   if (fGRF !=0 ) fGRF->Delete();
   fGRF = new TF2("FunCosh2D",  FunCosh2D,-5.,5.,-5.,5.,4);   
   funParam[0]=sigmaX;
@@ -376,7 +379,8 @@ void AliTPCPRF2D::SetGati(Float_t K3X, Float_t K3Y,
   fK3X=K3X;
   fK3Y=K3Y;
   fPadDistance=padDistance;  
-  sprintf(fType,"Gati");
+  //sprintf(fType,"Gati");
+  snprintf(fType,6,"Gati");
   if (fGRF !=0 ) fGRF->Delete();
   fGRF = new TF2("FunGati2D",  FunGati2D,-5.,5.,-5.,5.,5);  
  
@@ -703,7 +707,8 @@ TH1F *  AliTPCPRF2D::GenerDrawXHisto(Float_t x1, Float_t x2,Float_t y)
   //  at position y 
   char s[100]; 
   const Int_t kn=200;
-  sprintf(s,"Pad Response Function");  
+  //sprintf(s,"Pad Response Function"); 
+  snprintf(s,100,"Pad Response Function");  
   TH1F * hPRFc = new TH1F("hPRFc",s,kn+1,x1,x2);
   Float_t x=x1;
   Float_t y1;
@@ -724,7 +729,8 @@ AliH2F * AliTPCPRF2D::GenerDrawHisto(Float_t x1, Float_t x2, Float_t y1, Float_t
   //gener two dimensional histogram with PRF
   //
   char s[100];
-  sprintf(s,"Pad Response Function");  
+  //sprintf(s,"Pad Response Function"); 
+  snprintf(s,100,"Pad Response Function");  
   AliH2F * hPRFc = new AliH2F("hPRFc",s,Nx,x1,x2,Ny,y1,y2);
   Float_t dx=(x2-x1)/Float_t(Nx);
   Float_t dy=(y2-y1)/Float_t(Ny) ;
@@ -752,7 +758,8 @@ AliH2F * AliTPCPRF2D::GenerDrawDistHisto(Float_t x1, Float_t x2, Float_t y1, Flo
   const Float_t kminth=0.00001;
   if (thr<kminth) thr=kminth;
   char s[100]; 
-  sprintf(s,"COG distortion of PRF (threshold=%2.2f)",thr);  
+  //sprintf(s,"COG distortion of PRF (threshold=%2.2f)",thr); 
+  snprintf(s,100,"COG distortion of PRF (threshold=%2.2f)",thr); 
   AliH2F * hPRFDist = new AliH2F("hDistortion",s,Nx,x1,x2,Ny,y1,y2);
   Float_t dx=(x2-x1)/Float_t(Nx);
   Float_t dy=(y2-y1)/Float_t(Ny) ;
@@ -821,9 +828,11 @@ void AliTPCPRF2D::DrawX(Float_t x1 ,Float_t x2,Float_t y1,Float_t y2, Int_t N)
     else y = y1+i*(y2-y1)/Float_t(N-1);
     pad2->cd(i+1);
     TH1F * hPRFc =GenerDrawXHisto(x1, x2,y);
-    sprintf(ch,"PRF at wire position: %2.3f",y);
+    //sprintf(ch,"PRF at wire position: %2.3f",y);
+    snprintf(ch,40,"PRF at wire position: %2.3f",y);
     hPRFc->SetTitle(ch);  
-    sprintf(ch,"PRF %d",i);
+    //sprintf(ch,"PRF %d",i);
+    snprintf(ch,15,"PRF %d",i);
     hPRFc->SetName(ch);  
      hPRFc->Fit("gaus");
   }
@@ -894,55 +903,74 @@ void AliTPCPRF2D::DrawComment(TPaveText *comment)
   //draw comments to picture
   TText * title = comment->AddText("Pad Response Function  parameters:");
   title->SetTextSize(0.03);
-  sprintf(s,"Height of pad:  %2.2f cm",fHeightFull);
+  //sprintf(s,"Height of pad:  %2.2f cm",fHeightFull);
+  snprintf(s,100,"Height of pad:  %2.2f cm",fHeightFull);
   comment->AddText(s);
-  sprintf(s,"Width pad:  %2.2f cm",fWidth);
+  //sprintf(s,"Width pad:  %2.2f cm",fWidth);
+  snprintf(s,100,"Width pad:  %2.2f cm",fWidth);
   comment->AddText(s);
-  sprintf(s,"Pad Angle:  %2.2f ",fPadAngle);
+  //sprintf(s,"Pad Angle:  %2.2f ",fPadAngle);
+  snprintf(s,100,"Pad Angle:  %2.2f ",fPadAngle);
   comment->AddText(s);
   
   if (TMath::Abs(fK)>0.0001){
-    sprintf(s,"Height of one chevron unit h:  %2.2f cm",2*fHeightS);
+    //sprintf(s,"Height of one chevron unit h:  %2.2f cm",2*fHeightS);
+    snprintf(s,100,"Height of one chevron unit h:  %2.2f cm",2*fHeightS);
     comment->AddText(s);
-    sprintf(s,"Overlap factor:  %2.2f",fK);
+    //sprintf(s,"Overlap factor:  %2.2f",fK);
+    snprintf(s,100,"Overlap factor:  %2.2f",fK);
     comment->AddText(s); 
   }
 
   if (strncmp(fType,"User",3)==0){
-    sprintf(s,"Charge distribution - user defined function  %s ",fGRF->GetTitle());
+    //sprintf(s,"Charge distribution - user defined function  %s ",fGRF->GetTitle());
+    snprintf(s,100,"Charge distribution - user defined function  %s ",fGRF->GetTitle());
     comment->AddText(s);  
-    sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    //sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    snprintf(s,100,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);  
     comment->AddText(s);  
-    sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    //sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    snprintf(s,100,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
     comment->AddText(s); 
   }
   if (strncmp(fType,"Gauss",3)==0){
-    sprintf(s,"Gauss charge distribution");
+    //sprintf(s,"Gauss charge distribution");
+    snprintf(s,100,"Gauss charge distribution");
     comment->AddText(s);  
-    sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    //sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    snprintf(s,100,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
     comment->AddText(s);  
-    sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    //sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    snprintf(s,100,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
     comment->AddText(s); 
   }
   if (strncmp(fType,"Gati",3)==0){
-    sprintf(s,"Gati charge distribution");
+    //sprintf(s,"Gati charge distribution");
+    snprintf(s,100,"Gati charge distribution");
     comment->AddText(s);  
-    sprintf(s,"K3X of Gati : %2.2f ",fK3X);
+    //sprintf(s,"K3X of Gati : %2.2f ",fK3X);
+    snprintf(s,100,"K3X of Gati : %2.2f ",fK3X);
     comment->AddText(s);  
-    sprintf(s,"K3Y of Gati: %2.2f ",fK3Y);
+    //sprintf(s,"K3Y of Gati: %2.2f ",fK3Y);
+    snprintf(s,100,"K3Y of Gati: %2.2f ",fK3Y);
     comment->AddText(s); 
-    sprintf(s,"Wire to Pad Distance: %2.2f ",fPadDistance);
+    //sprintf(s,"Wire to Pad Distance: %2.2f ",fPadDistance);
+    snprintf(s,100,"Wire to Pad Distance: %2.2f ",fPadDistance);
     comment->AddText(s); 
   }
   if (strncmp(fType,"Cosh",3)==0){
-    sprintf(s,"Cosh charge distribution");
+    //sprintf(s,"Cosh charge distribution");
+    snprintf(s,100,"Cosh charge distribution");
     comment->AddText(s);  
-    sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    //sprintf(s,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
+    snprintf(s,100,"Sigma x of charge distribution: %2.2f ",fOrigSigmaX);
     comment->AddText(s);  
-    sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    //sprintf(s,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
+    snprintf(s,100,"Sigma y of charge distribution: %2.2f ",fOrigSigmaY);
     comment->AddText(s); 
   }
-  sprintf(s,"Normalisation: %2.2f ",fKNorm);
+  //sprintf(s,"Normalisation: %2.2f ",fKNorm);
+  snprintf(s,100,"Normalisation: %2.2f ",fKNorm);
   comment->AddText(s);    
 }
 
index 00c1c12..6e267a6 100644 (file)
@@ -198,7 +198,8 @@ void AliTPCRF1D::SetParam( TF1 * GRF,Float_t padwidth,
    if (sigma==0) sigma= fpadWidth/TMath::Sqrt(12.);
    forigsigma=sigma;
    fDSTEPM1 = 10/TMath::Sqrt(sigma*sigma+fpadWidth*fpadWidth/12); 
-   sprintf(fType,"User");
+   //sprintf(fType,"User");
+   snprintf(fType,6,"User");
    //   Update();   
 }
   
@@ -218,7 +219,8 @@ void AliTPCRF1D::SetGauss(Float_t sigma, Float_t padWidth,
   fGRF->SetParameters(funParam);
    fDSTEPM1 = 10./TMath::Sqrt(sigma*sigma+fpadWidth*fpadWidth/12); 
   //by default I set the step as one tenth of sigma  
-  sprintf(fType,"Gauss");
+  //sprintf(fType,"Gauss");
+   snprintf(fType,6,"Gauss");
 }
 
 void AliTPCRF1D::SetCosh(Float_t sigma, Float_t padWidth,
@@ -236,7 +238,8 @@ void AliTPCRF1D::SetCosh(Float_t sigma, Float_t padWidth,
   forigsigma=sigma;
   fDSTEPM1 = 10./TMath::Sqrt(sigma*sigma+fpadWidth*fpadWidth/12); 
   //by default I set the step as one tenth of sigma
-  sprintf(fType,"Cosh");
+  //sprintf(fType,"Cosh");
+  snprintf(fType,6,"Cosh");
 }
 
 void AliTPCRF1D::SetGati(Float_t K3, Float_t padDistance, Float_t padWidth,
@@ -255,7 +258,8 @@ void AliTPCRF1D::SetGati(Float_t K3, Float_t padDistance, Float_t padWidth,
   forigsigma=padDistance;
   fDSTEPM1 = 10./TMath::Sqrt(padDistance*padDistance+fpadWidth*fpadWidth/12); 
   //by default I set the step as one tenth of sigma
-  sprintf(fType,"Gati");
+  //sprintf(fType,"Gati");
+  snprintf(fType,6,"Gati");
 }
 
 
@@ -273,8 +277,9 @@ void AliTPCRF1D::DrawRF(Float_t x1,Float_t x2,Int_t N)
   TPad * pad2 = new TPad("pad2RF","",0.05,0.05,0.95,0.45,21);
   pad2->Draw();
 
-  sprintf(s,"RF response function for %1.2f cm pad width",
-         fpadWidth);  
+  //sprintf(s,"RF response function for %1.2f cm pad width",
+  //     fpadWidth); 
+  snprintf(s,60,"RF response function for %1.2f cm pad width",fpadWidth); 
   pad1->cd();
   TH1F * hRFo = new TH1F("hRFo","Original charge distribution",N+1,x1,x2);
   pad2->cd();
index d28c80a..f0307f2 100644 (file)
@@ -1065,20 +1065,23 @@ void AliTPCv2::CreateGeometry()
   TGeoCombiTrans *transf[13];
   Char_t name[30];
   for(Int_t i=0;i<13;i++){
-    sprintf(name,"transf%d",i);
+    //sprintf(name,"transf%d",i);
+    snprintf(name,30,"transf%d",i);
     transf[i]= new TGeoCombiTrans(name,0.,-2.,-9.+i*1.5,rhole);
     transf[i]->RegisterYourself();
   }
   // union expression for holes
   TString operl("hhole:transf0");
   for (Int_t i=1;i<13;i++){
-    sprintf(name,"+hhole:transf%d",i);
+    //sprintf(name,"+hhole:transf%d",i);
+    snprintf(name,30,"+hhole:transf%d",i);
     operl.Append(name);   
   }
   //
  TString opers("hhole:transf1");
   for (Int_t i=2;i<12;i++){
-    sprintf(name,"+hhole:transf%d",i);
+    //sprintf(name,"+hhole:transf%d",i);
+    snprintf(name,30,"+hhole:transf%d",i); 
     opers.Append(name);   
   }
   //union of holes