Fixing SECURE_CODING defects (sprintf) reported by Coverity
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 4 Nov 2010 22:36:26 +0000 (22:36 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 4 Nov 2010 22:36:26 +0000 (22:36 +0000)
MUON/AliMUONGain.cxx
MUON/AliMUONPedestalEventGenerator.cxx
MUON/AliMUONTrackLight.cxx
MUON/AliMUONTriggerCrateStore.cxx
MUON/AliMUONTriggerGUI.cxx
MUON/AliMUONTriggerGUIbdmap.cxx
MUON/AliMUONTriggerGUIdimap.cxx

index b010e79..e504d0f 100644 (file)
@@ -34,6 +34,7 @@
 #include <Riostream.h>
 
 #include <sstream>
+#include <cstdio>
 
 #define  NFITPARAMS 4
 
@@ -625,7 +626,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
              char bpmanuname[256];
              AliMUONErrorCounter* uncalcounter;
 
-             sprintf(bpmanuname,"bp%dmanu%d",busPatchId,manuId);
+             snprintf(bpmanuname,256,"bp%dmanu%d",busPatchId,manuId);
              if (!(uncalcounter = (AliMUONErrorCounter*)uncalBuspatchManuTable->FindObject(bpmanuname)))
                {
                  // New buspatch_manu name
@@ -659,14 +660,14 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
 
                      graphErr = new TGraphErrors(nEntries,pedMean,injCharge,pedSigma,injChargeErr);
 
-                     sprintf(graphName,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
+                     snprintf(graphName,256,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
 
                      graphErr->SetTitle(graphName);
                      graphErr->SetMarkerColor(3);
                      graphErr->SetMarkerStyle(12);
                      graphErr->Write(graphName);
 
-                     sprintf(graphName,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
+                     snprintf(graphName,256,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
                      f2Calib->SetTitle(graphName);
                      f2Calib->SetLineColor(4);
                      f2Calib->SetParameters(par);
index 6ee2958..a84cde9 100644 (file)
@@ -41,6 +41,8 @@
 #include <TStopwatch.h>
 #include <TSystem.h>
 
+#include <cstdio>
+
 //-----------------------------------------------------------------------------
 /// \class AliMUONPedestalEventGenerator
 ///
@@ -174,7 +176,7 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
     char command[256];
     // Note the option -s. It is used in order to avoid
     // the generation of SOR/EOR events.
-    sprintf(command, "dateStream -c -D -o %s.LDC%d -# %d -C", 
+    snprintf(command, 256, "dateStream -c -D -o %s.LDC%d -# %d -C", 
             fDateFileName.Data(), iFile, runLoader->GetNumberOfEvents());
     pipe[iFile] = gSystem->OpenPipe(command, "w");
   }
@@ -191,7 +193,7 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
       ldc += AliDAQ::NumberOfLdcs(kIDet) / AliDAQ::NumberOfDdls(kIDet);
       
       char rawFileName[256];
-      sprintf(rawFileName, "raw%d/%s", 
+      snprintf(rawFileName, 256, "raw%d/%s", 
               iEvent, AliDAQ::DdlFileName(kIDet,iDDL));
       
       // check existence and size of raw data file
@@ -220,7 +222,7 @@ AliMUONPedestalEventGenerator::ConvertRawFilesToDate()
   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); ++iEvent) 
   {
     char command[256];
-    sprintf(command, "rm -r raw%d", iEvent);
+    snprintf(command, 256, "rm -r raw%d", iEvent);
     gSystem->Exec(command);
   }
   
@@ -333,7 +335,7 @@ AliMUONPedestalEventGenerator::Digits2Raw(Int_t event)
   TString baseDir = gSystem->WorkingDirectory();
   
   char dirName[256];
-  sprintf(dirName, "raw%d", event);
+  snprintf(dirName, 256, "raw%d", event);
   gSystem->MakeDirectory(dirName);
   if (!gSystem->ChangeDirectory(dirName)) 
   {
index f15460c..805ae82 100644 (file)
@@ -50,6 +50,8 @@
 #include "TParticle.h"
 #include "TString.h"
 
+#include <cstdio>
+
 ClassImp(AliMUONTrackLight) 
 
 //===================================================================
@@ -328,22 +330,22 @@ void AliMUONTrackLight::PrintInfo(const Option_t* opt){
     TString pdg = "", line = "";
     for(int i = 3; i >= 0; i--){
       if(this->GetQuarkPythiaLine(i)>= 0){
-       sprintf(name, "%4d --> ", this->GetQuarkPythiaLine(i));
+       snprintf(name, 100, "%4d --> ", this->GetQuarkPythiaLine(i));
        line += name;
-       sprintf(name, "%4d --> ", this->GetQuarkPDGCode(i));
+       snprintf(name, 100, "%4d --> ", this->GetQuarkPDGCode(i));
        pdg += name;
       }
     }
     for(int i = 0; i < fNParents; i++){ 
       if(this->GetParentPythiaLine(i)>= 0){
-       sprintf(name, "%7d --> ", this->GetParentPythiaLine(i));
+       snprintf(name, 100, "%7d --> ", this->GetParentPythiaLine(i));
        line += name;
-       sprintf(name, "%7d --> ", this->GetParentPDGCode(i));
+       snprintf(name, 100, "%7d --> ", this->GetParentPDGCode(i));
        pdg += name;
       }
     }
-    sprintf(name, "%4d", this->GetTrackPythiaLine()); line += name;
-    sprintf(name, "%4d", this->GetTrackPDGCode()); pdg += name;
+    snprintf(name, 100, "%4d", this->GetTrackPythiaLine()); line += name;
+    snprintf(name, 100, "%4d", this->GetTrackPDGCode()); pdg += name;
 
     printf("\nmuon's decay history:\n");
     printf(" PDG: %s\n", pdg.Data());
index 0a98198..28ec0bc 100644 (file)
@@ -36,6 +36,8 @@
 #include <TSystem.h>
 #include <Riostream.h>
 
+#include <cstdio>
+
 //-----------------------------------------------------------------------------
 /// \class AliMUONTriggerCrateStore
 /// 
@@ -158,7 +160,7 @@ TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
   switch(reg) {
       case 0:
       case 1:
-       sprintf(name,"%d", reg+1);
+       snprintf(name,10,"%d", reg+1);
        break;
       case 2:
        strcpy(name, "2-3");
@@ -168,15 +170,15 @@ TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
       case 5:
       case 6:
       case 7:
-       sprintf(name,"%d", reg);
+       snprintf(name,10,"%d", reg);
        break;
   }
 
   // crate Right for first DDL
   if (ddl == 0)
-    strcat(name, "R");
+    strncat(name, "R", 1);
   else 
-    strcat(name, "L"); 
+    strncat(name, "L", 1); 
 
   return TString(name);
 }
index b03bd3e..08a182c 100644 (file)
@@ -71,6 +71,8 @@
 #include <TGImageMap.h>
 #include <TGTextBuffer.h>
 
+#include <cstdio>
+
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerGUI)
 /// \endcond
@@ -1372,22 +1374,22 @@ void AliMUONTriggerGUI::OpenBoard(Int_t id)
   bf = new AliMUONTriggerGUIbdmap(gClient->GetRoot(), fMain, 400, 200);
 
   if (status & kGood) {
-    sprintf(text,"%s (Circuit %4d) status : working",
+    snprintf(text,200,"%s (Circuit %4d) status : working",
            board->GetBoardName(),board->GetIdCircuit());
   }
 
   if (status & kWithProblems) {
-    sprintf(text,"%s (Circuit %4d)  status : has problems...",
+    snprintf(text,200,"%s (Circuit %4d)  status : has problems...",
            board->GetBoardName(),board->GetIdCircuit());
   }
 
   if (status & kNotWorking) {
-    sprintf(text,"%s (Circuit %4d)  status : not working",
+    snprintf(text,200,"%s (Circuit %4d)  status : not working",
            board->GetBoardName(),board->GetIdCircuit());
   }
 
   if (status & kUnknown) {
-    sprintf(text,"%s (Circuit %4d)  status : unknown",
+    snprintf(text,200,"%s (Circuit %4d)  status : unknown",
            board->GetBoardName(),board->GetIdCircuit());
   }
 
@@ -1586,7 +1588,7 @@ void AliMUONTriggerGUI::InitBoards()
     reg = new TGRegion(5,xp,yp);
     fImageMap->AddRegion(*reg, ib);
 
-    sprintf(text,"%s (crate %s circuit %3d, number %3d)",board->GetBoardName(),board->GetCrateName(),board->GetIdCircuit(),board->GetNumber());
+    snprintf(text,256,"%s (crate %s circuit %3d, number %3d)",board->GetBoardName(),board->GetCrateName(),board->GetIdCircuit(),board->GetNumber());
     fImageMap->SetToolTipText(ib, text);
 
     // Set coordinates of strips boxes
index c94de21..b5f35af 100644 (file)
@@ -53,6 +53,8 @@
 #include "AliMpVSegmentation.h"
 #include "AliMpSegmentation.h"
 
+#include <cstdio>
+
 
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerGUIbdmap)
@@ -104,10 +106,10 @@ AliMUONTriggerGUIbdmap::AliMUONTriggerGUIbdmap(const TGWindow *p, const TGWindow
   fCanvasSize = 200;
 
   TRootEmbeddedCanvas *recanvas[4];
-  Char_t ecname[1];
+  Char_t ecname[2];
   for (Int_t i = 0; i < kNMT; i++) {
 
-    sprintf(ecname,"%1d",i+1);
+    snprintf(ecname,2,"%1d",i+1);
     recanvas[i] = new TRootEmbeddedCanvas(ecname,fMain,fCanvasSize,fCanvasSize);
     
     fCanvas[i] = recanvas[i]->GetCanvas();
@@ -282,7 +284,7 @@ void AliMUONTriggerGUIbdmap::LocalTriggerInfo()
   TGText txt;
   Char_t buffer[20];
 
-  sprintf(buffer,"Local trigger info\n");
+  snprintf(buffer,20,"Local trigger info\n");
   fLocTrigE->LoadBuffer(buffer);
 
   AliMUONVTriggerStore *triggerStore;
@@ -293,7 +295,7 @@ void AliMUONTriggerGUIbdmap::LocalTriggerInfo()
   } else if (fRawTriggerStore != 0x0) {
     triggerStore = static_cast<AliMUONVTriggerStore*>(fRawTriggerStore);
   } else {
-    sprintf(buffer,"No data loaded yet...\n");
+    snprintf(buffer,20,"No data loaded yet...\n");
     txt.LoadBuffer(buffer);
     fLocTrigE->AddText(&txt);
     return;
@@ -332,43 +334,43 @@ void AliMUONTriggerGUIbdmap::LocalTriggerInfo()
        iStripY = loStripY;
       }
 
-      sprintf(buffer,"Circuit = %03d",loCircuit);
+      snprintf(buffer,20,"Circuit = %03d",loCircuit);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"LoStripX = %2d",loStripX);
+      snprintf(buffer,20,"LoStripX = %2d",loStripX);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"LoStripY = %2d",loStripY);
+      snprintf(buffer,20,"LoStripY = %2d",loStripY);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"LoDev = %2d",loDev);
+      snprintf(buffer,20,"LoDev = %2d",loDev);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"--------------------");
+      snprintf(buffer,20,"--------------------");
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"X-strip = %2d ( %2d )",iStripX,(loStripX+loDev+1)/2);
+      snprintf(buffer,20,"X-strip = %2d ( %2d )",iStripX,(loStripX+loDev+1)/2);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"Y-strip = %2d",iStripY);
+      snprintf(buffer,20,"Y-strip = %2d",iStripY);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"--------------------");
+      snprintf(buffer,20,"--------------------");
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"LoLpt = %2d",loLpt);
+      snprintf(buffer,20,"LoLpt = %2d",loLpt);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
-      sprintf(buffer,"LoHpt = %2d",loHpt);
+      snprintf(buffer,20,"LoHpt = %2d",loHpt);
       txt.LoadBuffer(buffer);
       fLocTrigE->AddText(&txt);
 
@@ -460,7 +462,7 @@ void AliMUONTriggerGUIbdmap::EditStrips(Int_t event, Int_t x, Int_t y, TObject *
   Int_t np = 5;
   Double_t xMin, xMax, yMin, yMax;
   Float_t xd, yd, fxDim, fyDim, cDim;
-  Char_t cln[2];
+  Char_t cln[3];
 
   cDim = (Float_t)fCanvasSize;
   
@@ -511,7 +513,7 @@ void AliMUONTriggerGUIbdmap::EditStrips(Int_t event, Int_t x, Int_t y, TObject *
              fXDigBox[iMT][ix]->SetFillStyle(1001);
              fXDigBox[iMT][ix]->SetFillColor(2);
 
-             sprintf(cln,"%2d",ix);
+             snprintf(cln,3,"%2d",ix);
 
              fXLabelL[iMT][ix]->Clear();
              fXLabelL[iMT][ix]->AddText(cln);
@@ -585,7 +587,7 @@ void AliMUONTriggerGUIbdmap::EditStrips(Int_t event, Int_t x, Int_t y, TObject *
              fYDigBox[iMT][iy]->SetFillStyle(1001);
              fYDigBox[iMT][iy]->SetFillColor(2);
 
-             sprintf(cln,"%2d",iy);
+             snprintf(cln,3,"%2d",iy);
 
              fYLabelL[iMT][iy]->Clear();
              fYLabelL[iMT][iy]->AddText(cln);
@@ -975,7 +977,7 @@ void AliMUONTriggerGUIbdmap::DrawDigits(Bool_t bx, Bool_t by)
            fXDigBox[i][iy-iY1]->SetY2(ypmax);
            fXDigBox[i][iy-iY1]->Draw();
            
-           sprintf(cln,"%2d",(iy-iY1));
+           snprintf(cln,3,"%2d",(iy-iY1));
            fXLabelL[i][iy-iY1]->Clear();
            fXLabelL[i][iy-iY1]->AddText(cln);
            fXLabelL[i][iy-iY1]->Draw();
@@ -1025,7 +1027,7 @@ void AliMUONTriggerGUIbdmap::DrawDigits(Bool_t bx, Bool_t by)
            fYDigBox[i][ix-iX1]->SetY2(ypmax);
            fYDigBox[i][ix-iX1]->Draw();
            
-           sprintf(cln,"%2d",(ix-iX1));
+           snprintf(cln,3,"%2d",(ix-iX1));
            fYLabelL[i][ix-iX1]->Clear();
            fYLabelL[i][ix-iX1]->AddText(cln);
            fYLabelL[i][ix-iX1]->Draw();
@@ -1091,7 +1093,7 @@ void AliMUONTriggerGUIbdmap::DrawDigits(Bool_t bx, Bool_t by)
            fXDigBox[i][ix]->SetY2(yMax);
          }
          
-         sprintf(cln,"%2d",ix);
+         snprintf(cln,3,"%2d",ix);
          
          fXLabelL[i][ix]->Clear();
          fXLabelL[i][ix]->AddText(cln);
@@ -1140,7 +1142,7 @@ void AliMUONTriggerGUIbdmap::DrawDigits(Bool_t bx, Bool_t by)
            fYDigBox[i][iy]->SetY2(yMax);
          }
          
-         sprintf(cln,"%2d",iy);
+         snprintf(cln,3,"%2d",iy);
          
          fYLabelL[i][iy]->Clear();
          fYLabelL[i][iy]->AddText(cln);
@@ -1287,7 +1289,7 @@ void AliMUONTriggerGUIbdmap::DrawStrips(Bool_t bx, Bool_t by)
              fYDigBox[i][ixDig]->DrawBox(xpmin,ypmin,xpmax,ypmax);
              */
              if (makeLabelsY) {
-               sprintf(cln,"%2d",(ix-iX1));
+               snprintf(cln,3,"%2d",(ix-iX1));
                ptx1 = xpmin;
                ptx2 = xpmax;
                
@@ -1378,7 +1380,7 @@ void AliMUONTriggerGUIbdmap::DrawStrips(Bool_t bx, Bool_t by)
              fXDigBox[i][iyDig]->DrawBox(xpmin,ypmin,xpmax,ypmax);
              */
              if (makeLabelsX) {
-               sprintf(cln,"%2d",(iy-iY1));
+               snprintf(cln,3,"%2d",(iy-iY1));
                pty1 = ypmin;
                pty2 = ypmax;
                
index 257b9e5..5eaf6ea 100644 (file)
@@ -46,6 +46,8 @@
 
 #include "AliMUONDigitStoreV1.h"
 
+#include <cstdio>
+
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerGUIdimap)
 /// \endcond
@@ -255,7 +257,7 @@ void AliMUONTriggerGUIdimap::DrawMaps(Int_t chamber)
   TPaveText *label;
   TBox *boxd;
 
-  Char_t cln[2];
+  Char_t cln[3];
   Int_t detElemId, cathode, ix, iy, charge, color;
   Int_t holdS, holdL, holdC;
   Float_t xCenter, yCenter, xWidth, yWidth, holdXC, holdYC;
@@ -324,7 +326,7 @@ void AliMUONTriggerGUIdimap::DrawMaps(Int_t chamber)
 
     if (holdL == 9) {
 
-      sprintf(cln,"C%1d",holdC);
+      snprintf(cln,3,"C%1d",holdC);
 
       ptx1 = holdXC - lWidth;
       ptx2 = holdXC + lWidth;
@@ -339,7 +341,7 @@ void AliMUONTriggerGUIdimap::DrawMaps(Int_t chamber)
     }
     if (holdL == 1) {
 
-      sprintf(cln,"C%1d",holdC);
+      snprintf(cln,3,"C%1d",holdC);
 
       ptx1 = holdXC - lWidth;
       ptx2 = holdXC + lWidth;
@@ -354,7 +356,7 @@ void AliMUONTriggerGUIdimap::DrawMaps(Int_t chamber)
     }
     if (holdS == 0 && holdC == 7) {
 
-      sprintf(cln,"L%1d",holdL);
+      snprintf(cln,3,"L%1d",holdL);
 
       ptx1 = -1.07*frameXmax - lWidth;
       ptx2 = -1.07*frameXmax + lWidth;
@@ -369,7 +371,7 @@ void AliMUONTriggerGUIdimap::DrawMaps(Int_t chamber)
     }
     if (holdS == 1 && holdC == 7) {
 
-      sprintf(cln,"L%1d",holdL);
+      snprintf(cln,3,"L%1d",holdL);
 
       ptx1 = +1.07*frameXmax - lWidth;
       ptx2 = +1.07*frameXmax + lWidth;