From 90ae05038072bb6482c77a3d58e081041a43734d Mon Sep 17 00:00:00 2001 From: abercuci Date: Wed, 27 Oct 2010 12:14:14 +0000 Subject: [PATCH] fix coverity --- EVE/EveDet/AliEveTRDData.cxx | 11 +++-- EVE/EveDet/AliEveTRDLoader.cxx | 5 ++- EVE/EveDet/AliEveTRDLoaderImp.cxx | 2 +- EVE/EveDet/AliEveTRDLoaderManager.cxx | 3 +- EVE/EveDet/AliEveTRDModule.cxx | 5 ++- EVE/EveDet/AliEveTRDModuleImp.cxx | 3 +- EVE/EveDet/AliEveTRDTrackList.cxx | 58 ++++++++++++------------- EVE/EveDet/AliEveTRDTrackList.h | 6 +-- EVE/EveDet/AliEveTRDTrackListEditor.cxx | 49 ++++++++------------- 9 files changed, 66 insertions(+), 76 deletions(-) diff --git a/EVE/EveDet/AliEveTRDData.cxx b/EVE/EveDet/AliEveTRDData.cxx index 8beae5e5edb..6ca4f1bba32 100644 --- a/EVE/EveDet/AliEveTRDData.cxx +++ b/EVE/EveDet/AliEveTRDData.cxx @@ -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(*itrklt)->Load(what); + if((trklt = dynamic_cast(*itrklt))) trklt->Load(what); itrklt++; } } - +//______________________________________________________________________________ AliEveTRDTrackletOnline::AliEveTRDTrackletOnline(AliTRDtrackletMCM *tracklet) : TEveLine(), fDetector(-1), diff --git a/EVE/EveDet/AliEveTRDLoader.cxx b/EVE/EveDet/AliEveTRDLoader.cxx index bd228d1765f..5b323abba0a 100644 --- a/EVE/EveDet/AliEveTRDLoader.cxx +++ b/EVE/EveDet/AliEveTRDLoader.cxx @@ -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(*ichmb))->Paint(option); + if((module = dynamic_cast(*ichmb))) module->Paint(option); ichmb++; } } @@ -471,7 +472,7 @@ void AliEveTRDLoaderEditor::SetModel(TObject* obj) { // Set model object. - fM = dynamic_cast(obj); + if(!(fM = dynamic_cast(obj))) return; fFile->SetEnabled(!fM->IsDataLinked()); fFile->SetText(gSystem->BaseName(fM->fFilename.Data())); diff --git a/EVE/EveDet/AliEveTRDLoaderImp.cxx b/EVE/EveDet/AliEveTRDLoaderImp.cxx index a743d7e1b72..eac2361d4be 100644 --- a/EVE/EveDet/AliEveTRDLoaderImp.cxx +++ b/EVE/EveDet/AliEveTRDLoaderImp.cxx @@ -305,7 +305,7 @@ void AliEveTRDLoaderSimEditor::SetModel(TObject* obj) { // Set model object. - fM = dynamic_cast(obj); + if(!(fM = dynamic_cast(obj))) return; Bool_t kRL = (fM->IsDataLinked()) ? kTRUE : kFALSE; diff --git a/EVE/EveDet/AliEveTRDLoaderManager.cxx b/EVE/EveDet/AliEveTRDLoaderManager.cxx index 5eaa217ff1f..8559aaca0f9 100644 --- a/EVE/EveDet/AliEveTRDLoaderManager.cxx +++ b/EVE/EveDet/AliEveTRDLoaderManager.cxx @@ -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(*ichmb))->Paint(option); + if((loader = dynamic_cast(*ichmb))) loader->Paint(option); ichmb++; } } diff --git a/EVE/EveDet/AliEveTRDModule.cxx b/EVE/EveDet/AliEveTRDModule.cxx index 218041decca..3be4d79a0cd 100644 --- a/EVE/EveDet/AliEveTRDModule.cxx +++ b/EVE/EveDet/AliEveTRDModule.cxx @@ -167,7 +167,7 @@ void AliEveTRDModuleEditor::SetModel(TObject* obj) { // Set model object. - fM = dynamic_cast(obj); + if(!(fM = dynamic_cast(obj))) return; if(AliEveTRDNode *node = dynamic_cast(fM)) node->UpdateNode(); @@ -241,7 +241,8 @@ void AliEveTRDModuleEditor::UpdateChamber() fM->fRnrTracklets = kFALSE; if(fDisplayTracks->IsDown()) fM->fRnrTracklets = kTRUE; - if(dynamic_cast(fM)) (dynamic_cast(fM))->UpdateLeaves(); + AliEveTRDNode *node(NULL); + if((node = dynamic_cast(fM))) node->UpdateLeaves(); gEve->Redraw3D(); } diff --git a/EVE/EveDet/AliEveTRDModuleImp.cxx b/EVE/EveDet/AliEveTRDModuleImp.cxx index ee6a1f464e5..ba7056f357b 100644 --- a/EVE/EveDet/AliEveTRDModuleImp.cxx +++ b/EVE/EveDet/AliEveTRDModuleImp.cxx @@ -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(*iter))->Paint(option); + if((module = dynamic_cast(*iter))) module->Paint(option); iter++; } } diff --git a/EVE/EveDet/AliEveTRDTrackList.cxx b/EVE/EveDet/AliEveTRDTrackList.cxx index 68450f37c9d..c762ed5fe06 100644 --- a/EVE/EveDet/AliEveTRDTrackList.cxx +++ b/EVE/EveDet/AliEveTRDTrackList.cxx @@ -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(); diff --git a/EVE/EveDet/AliEveTRDTrackList.h b/EVE/EveDet/AliEveTRDTrackList.h index b16b1ecd732..e09c3b757d9 100644 --- a/EVE/EveDet/AliEveTRDTrackList.h +++ b/EVE/EveDet/AliEveTRDTrackList.h @@ -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 { diff --git a/EVE/EveDet/AliEveTRDTrackListEditor.cxx b/EVE/EveDet/AliEveTRDTrackListEditor.cxx index 7a47c0dd9fc..3a17f886be7 100644 --- a/EVE/EveDet/AliEveTRDTrackListEditor.cxx +++ b/EVE/EveDet/AliEveTRDTrackListEditor.cxx @@ -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; } //______________________________________________________ -- 2.43.0