]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
fix coverity
authorabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 27 Oct 2010 12:14:14 +0000 (12:14 +0000)
committerabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 27 Oct 2010 12:14:14 +0000 (12:14 +0000)
EVE/EveDet/AliEveTRDData.cxx
EVE/EveDet/AliEveTRDLoader.cxx
EVE/EveDet/AliEveTRDLoaderImp.cxx
EVE/EveDet/AliEveTRDLoaderManager.cxx
EVE/EveDet/AliEveTRDModule.cxx
EVE/EveDet/AliEveTRDModuleImp.cxx
EVE/EveDet/AliEveTRDTrackList.cxx
EVE/EveDet/AliEveTRDTrackList.h
EVE/EveDet/AliEveTRDTrackListEditor.cxx

index 8beae5e5edbafee0b3875c652cd170d66c7cc6dc..6ca4f1bba32e6bfeb5fda1382644e6ec5ccdf177 100644 (file)
@@ -572,7 +572,7 @@ void AliEveTRDTrack::SetStatus(UChar_t s)
     1.E2*trk->GetPID(2), 1.E2*trk->GetPID(3), 1.E2*trk->GetPID(4), trk->GetLabel()));
 
   if(GetName()){
-    char id[6]; strncpy(id, GetName(), 6); 
+    char id[6]; snprintf(id, 6, "%s", GetName());
     SetName(Form("%s %s", id, AliPID::ParticleName(species)));
   }
 
@@ -583,14 +583,17 @@ void AliEveTRDTrack::SetStatus(UChar_t s)
 //______________________________________________________________________________
 void AliEveTRDTrack::Load(Char_t *what) const
 {
-  TEveElement::List_ci itrklt=BeginChildren();
+// Spread downwards to tracklets the command "what"
+
+  const AliEveTRDTracklet* trklt(NULL);
+  TEveElement::List_ci itrklt=BeginChildren();
   while(itrklt!=EndChildren()){
-    dynamic_cast<const AliEveTRDTracklet*>(*itrklt)->Load(what);
+    if((trklt = dynamic_cast<const AliEveTRDTracklet*>(*itrklt))) trklt->Load(what);
     itrklt++;
   }
 }
 
-
+//______________________________________________________________________________
 AliEveTRDTrackletOnline::AliEveTRDTrackletOnline(AliTRDtrackletMCM *tracklet) :
   TEveLine(),
   fDetector(-1),
index bd228d1765f664e3b1a9258c56a05fd927973475..5b323abba0a45fdbb52556a25cf72760dac1c60f 100644 (file)
@@ -336,9 +336,10 @@ void AliEveTRDLoader::Paint(Option_t *option)
 {
   // Paint object.
 
+  AliEveTRDModule *module(NULL);
   List_i ichmb = fChildren.begin();
   while(ichmb != fChildren.end()){
-    (dynamic_cast<AliEveTRDModule*>(*ichmb))->Paint(option);
+    if((module = dynamic_cast<AliEveTRDModule*>(*ichmb))) module->Paint(option);
     ichmb++;
   }
 }
@@ -471,7 +472,7 @@ void AliEveTRDLoaderEditor::SetModel(TObject* obj)
 {
   // Set model object.
 
-  fM = dynamic_cast<AliEveTRDLoader*>(obj);
+  if(!(fM = dynamic_cast<AliEveTRDLoader*>(obj))) return;
 
   fFile->SetEnabled(!fM->IsDataLinked());
   fFile->SetText(gSystem->BaseName(fM->fFilename.Data()));
index a743d7e1b727c9f664827693eded1261541f1b2f..eac2361d4be4b64c8c2566a73b24d009d4571f98 100644 (file)
@@ -305,7 +305,7 @@ void AliEveTRDLoaderSimEditor::SetModel(TObject* obj)
 {
   // Set model object.
 
-  fM = dynamic_cast<AliEveTRDLoaderSim*>(obj);
+  if(!(fM = dynamic_cast<AliEveTRDLoaderSim*>(obj))) return;
 
   Bool_t kRL   = (fM->IsDataLinked()) ? kTRUE : kFALSE;
 
index 5eaa217ff1fca8c106480ae24404480a25fe3705..8559aaca0f975c558192b727095bbc2936cf8a84 100644 (file)
@@ -70,9 +70,10 @@ void AliEveTRDLoaderManager::Paint(Option_t *option)
 {
   // Paint object.
 
+  AliEveTRDLoader *loader(NULL);
   List_i ichmb = fChildren.begin();
   while(ichmb != fChildren.end()){
-    (dynamic_cast<AliEveTRDLoader*>(*ichmb))->Paint(option);
+    if((loader = dynamic_cast<AliEveTRDLoader*>(*ichmb))) loader->Paint(option);
     ichmb++;
   }
 }
index 218041deccaffaf36d5ce67ffebd4c9ca142795a..3be4d79a0cd894c2908cef5230644ef82b6a353d 100644 (file)
@@ -167,7 +167,7 @@ void AliEveTRDModuleEditor::SetModel(TObject* obj)
 {
   // Set model object.
 
-  fM = dynamic_cast<AliEveTRDModule*>(obj);
+  if(!(fM = dynamic_cast<AliEveTRDModule*>(obj))) return;
 
   if(AliEveTRDNode *node = dynamic_cast<AliEveTRDNode*>(fM)) node->UpdateNode();
 
@@ -241,7 +241,8 @@ void AliEveTRDModuleEditor::UpdateChamber()
   fM->fRnrTracklets = kFALSE;
   if(fDisplayTracks->IsDown()) fM->fRnrTracklets = kTRUE;
 
-  if(dynamic_cast<AliEveTRDNode*>(fM)) (dynamic_cast<AliEveTRDNode*>(fM))->UpdateLeaves();
+  AliEveTRDNode *node(NULL);
+  if((node = dynamic_cast<AliEveTRDNode*>(fM))) node->UpdateLeaves();
 
   gEve->Redraw3D();
 }
index ee6a1f464e5d3babc59470da15b43f3d36c6e225..ba7056f357bdc2393852bfac256dfff4e6cdacd2 100644 (file)
@@ -48,9 +48,10 @@ void AliEveTRDNode::Paint(Option_t* option)
 {
   // Paint object.
 
+  AliEveTRDModule *module(NULL);
   List_i iter = fChildren.begin();
   while(iter != fChildren.end()){
-    (dynamic_cast<AliEveTRDModule*>(*iter))->Paint(option);
+    if((module = dynamic_cast<AliEveTRDModule*>(*iter))) module->Paint(option);
     iter++;
   }
 }
index 68450f37c9d1fb1971a543f74fb52368efa7f38c..c762ed5fe063000137308e3a8c4ad8b14aff48ff 100644 (file)
@@ -173,7 +173,7 @@ Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC, Bool
 
   // Expand the path and create the pathname
   Char_t* systemPath = gSystem->ExpandPathName(path);
-  sprintf(pathname, "%s/%s", systemPath, nameC);
+  snprintf(pathname, fkMaxMacroPathNameLength, "%s/%s", systemPath, nameC);
   delete systemPath;
   systemPath = 0;
 
@@ -334,7 +334,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
   // A.B. gROOT->Reset();
   
   // Clear old data and re-allocate
-  if (fDataTree == 0x0){ 
+  if (!fDataTree){
     TDirectory *cwd = gDirectory;
     fDataTree = new TTreeSRedirector(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")));
     cwd->cd();
@@ -356,15 +356,11 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
 
   TMacroData* macro = 0;
 
-  TString* procCmds = 0;
-  AliEveTRDTrackListMacroType* mProcType = 0;
-  if (procIterator->GetEntries() > 0) {
-    procCmds = new TString[procIterator->GetEntries()];
-    mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()];
-  }
+  TString* procCmds = new TString[procIterator->GetEntries()];
+  AliEveTRDTrackListMacroType* mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()];
 
   TString* selCmds(NULL);
-  AliEveTRDTrackListMacroType* mSelType = 0;
+  AliEveTRDTrackListMacroType* mSelType(NULL);
   if (selIterator->GetEntries() > 0) {
     selCmds = new TString[selIterator->GetEntries()];
     mSelType = new AliEveTRDTrackListMacroType[selIterator->GetEntries()];
@@ -374,7 +370,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
 
   AliEveTRDTrackListMacroType macroType = kUnknown;
   Int_t numHistoMacros = 0;
-  TH1** histos = 0;
+  TH1** histos(NULL);
 
   AliEveTRDTrack* track1(NULL);
   AliEveTRDTrack* track2(NULL);
@@ -440,25 +436,25 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
     // Single track select macro
     if (macroType == kSingleTrackSelect) {
       // Has already been processed by ApplySTSelectionMacros(...)
-      mSelType[i] = macroType;         
+      if(mSelType) mSelType[i] = macroType;
     }
     // Correlated tracks select macro
     else if (macroType == kCorrelTrackSelect) {
-      mSelType[i] = macroType;  
+      if(mSelType) mSelType[i] = macroType;  
  
       // Create the command
-      selCmds[i] = macro->GetCmd();
+      if(selCmds) selCmds[i] = macro->GetCmd();
     } else {
       Error("Apply process macros", 
         Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!", 
         macro->GetPath(), macro->GetName()));
-      mSelType[i] = kUnknown;
+      if(mSelType) mSelType[i] = kUnknown;
     } 
   }  
 
   // Allocate memory for the histograms
   if (numHistoMacros > 0)  histos = new TH1*[numHistoMacros];
-  for (Int_t i = 0; i < numHistoMacros; i++)  histos[i] = 0x0;
+  memset(histos, 0, numHistoMacros*sizeof(TH1*));
 
 
   //////////////////////////////////
@@ -478,7 +474,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
     for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries(); i++){
       // Single track histo
       if (mProcType[i] == kSingleTrackHisto){
-        histos[histoIndex++] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
+        if(histos) histos[histoIndex++] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
        // Correlated tracks histo
       } else if (mProcType[i] == kCorrelTrackHisto) {
         // Loop over all pairs behind the current one - together with the other loop this will be a loop
@@ -502,7 +498,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
           // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
           selectedByCorrSelMacro = kTRUE;
           for (Int_t j = 0; j < selIterator->GetEntries(); j++){
-            if (mSelType[j] == kCorrelTrackSelect){
+            if (mSelType && mSelType[j] == kCorrelTrackSelect){
               selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
               if (!selectedByCorrSelMacro)  break;
             }
@@ -511,7 +507,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
           // If the pair has not been selected by the correlated tracks selection macros, skip it!
           if (!selectedByCorrSelMacro) continue;
           
-          histos[histoIndex] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
+          if(histos) histos[histoIndex] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
         }
         histoIndex++;
       }
@@ -558,7 +554,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
           // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
           selectedByCorrSelMacro = kTRUE;
           for (Int_t j = 0; j < selIterator->GetEntries(); j++) {
-            if (mSelType[j] == kCorrelTrackSelect) {
+            if (mSelType && mSelType[j] == kCorrelTrackSelect) {
               selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
               if (!selectedByCorrSelMacro)  break;
             }
@@ -599,21 +595,21 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL
     }
   }
 
-  if (fDataTree != 0) delete fDataTree;
-  fDataTree = 0;
+  if (fDataTree) delete fDataTree;
+  fDataTree = NULL;
 
-  if (procCmds != 0)  delete [] procCmds;
-  procCmds = 0;
-  if (mProcType != 0)  delete [] mProcType;
-  mProcType = 0;
+  if (procCmds)  delete [] procCmds;
+  procCmds = NULL;
+  if (mProcType)  delete [] mProcType;
+  mProcType = NULL;
 
-  if (selCmds != 0)  delete [] selCmds;
-  selCmds = 0;
-  if (mSelType != 0)  delete [] mSelType;
-  mSelType = 0;
+  if (selCmds)  delete [] selCmds;
+  selCmds = NULL;
+  if (mSelType)  delete [] mSelType;
+  mSelType = NULL;
 
-  if (histos != 0)  delete [] histos;
-  histos = 0;
+  if (histos)  delete [] histos;
+  histos = NULL;
 
   // Clear root
   // A.B. gROOT->Reset();
index b16b1ecd732078bbddd51b3b9aac9d2df299ff2b..e09c3b757d92f4b624cff6d363f31b7c2be7562e 100644 (file)
@@ -279,17 +279,17 @@ public:
   void SetCmd(const char* newCmd)             // Sets the command that will be used to call this macro
   { 
     memset(fCmd, '\0', sizeof(Char_t) * MAX_APPLY_COMMAND_LENGTH);
-    sprintf(fCmd, "%s", newCmd);
+    snprintf(fCmd, MAX_APPLY_COMMAND_LENGTH, "%s", newCmd);
   }
   void SetName(const char* newName)           // Sets the macro name (please use without ".C")
   { 
     memset(fName, '\0', sizeof(Char_t) * MAX_MACRO_NAME_LENGTH);
-    sprintf(fName, "%s", newName);
+    snprintf(fName, MAX_MACRO_NAME_LENGTH, "%s", newName);
   }
   void SetPath(const char* newPath)           // Sets the path of the macro
   { 
     memset(fPath, '\0', sizeof(Char_t) * MAX_MACRO_PATH_LENGTH);
-    sprintf(fPath, "%s", newPath);
+    snprintf(fPath, MAX_MACRO_PATH_LENGTH, "%s", newPath);
   }
   void SetSelected(Bool_t selection)          // Sets whether the macro is selected or not
   {
index 7a47c0dd9fc2a8b2692da32164f48bf2c50b83a3..3a17f886be7d996810264e85c6db0c2c7b0552ea 100644 (file)
@@ -332,13 +332,10 @@ void AliEveTRDTrackListEditor::ApplyMacros()
     DrawHistos();
   }
 
-  if (selIterator != 0) delete selIterator;
-  selIterator = 0;  
-  if (procIterator != 0)  delete procIterator;  
-  procIterator = 0;  
+  delete selIterator;
+  delete procIterator;  
   
-  if (!success)
-  {
+  if (!success) {
     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
                  "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!", 
                  kMBIconExclamation, kMBOk);  
@@ -652,6 +649,8 @@ void AliEveTRDTrackListEditor::HandleMacroPathSet()
   // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
   // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
 
+  Char_t bname[AliEveTRDTrackList::fkMaxMacroNameLength]; // allocate buffers
+
   if (strlen(fteField->GetText()) != 0)
   {  
     // Expand the pathname
@@ -672,36 +671,30 @@ void AliEveTRDTrackListEditor::HandleMacroPathSet()
       Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
 
       // Current path
-      if (name == NULL)
-      {
-        name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength];
+      if (!name) {
+        name= bname;
         memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
-        sprintf(name, "%s", fteField->GetText());
+        snprintf(name, AliEveTRDTrackList::fkMaxMacroNameLength, "%s", fteField->GetText());
 
         // Add path to textfield -> Path is "./" -> Use length for the name + 2
         Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
         memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
-        sprintf(pathname, "./%s", fteField->GetText());
+        snprintf(pathname, AliEveTRDTrackList::fkMaxMacroNameLength + 2, "./%s", fteField->GetText());
         fteField->SetText(pathname);
 
         AddMacro(name);  
-        if (name != 0)  delete [] name;
-        name = 0;
       }
       // Different path
       else
       {
         // Extract path
-        Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength];
+        Char_t path[AliEveTRDTrackList::fkMaxMacroPathLength];
         memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
-        strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
+        snprintf(path, strlen(fteField->GetText()) - strlen(name), "%s", fteField->GetText());
         
         // Ignore the slash "/" in name
         AddMacro(name + 1, path);  
-  
-        if (path != 0)  delete [] path;
-        path = 0;
-      }       
+      }
     }
     else
     {
@@ -798,24 +791,18 @@ void AliEveTRDTrackListEditor::RemoveMacros()
 {
   // Removes the selected macros from the corresponding list.
 
-  TList* iterator = new TList();
-  
-  ftlMacroList->GetSelectedEntries(iterator);
-  fM->RemoveSelectedMacros(iterator);
+  TList iterator;
+  ftlMacroList->GetSelectedEntries(&iterator);
+  fM->RemoveSelectedMacros(&iterator);
 
-  if (iterator != 0)  delete iterator;
 
-  iterator = new TList();
-  ftlMacroSelList->GetSelectedEntries(iterator);
-  fM->RemoveSelectedMacros(iterator);
+  iterator.Clear();
+  ftlMacroSelList->GetSelectedEntries(&iterator);
+  fM->RemoveSelectedMacros(&iterator);
 
   // Selected macros are deleted from the list -> No selected entries left
   fM->fMacroListSelected = 0;
-
   UpdateMacroList();
-
-  if (iterator != 0)  delete iterator;
-  iterator = 0;
 }
 
 //______________________________________________________