From 3c53395bb55ed1ce495a6739d4500e019216eb2a Mon Sep 17 00:00:00 2001
From: Bertrand Bellenot <Bertrand.Bellenot@cern.ch>
Date: Wed, 5 Oct 2011 13:33:57 +0000
Subject: [PATCH] Fix coverity reports (dereference null value)

git-svn-id: http://root.cern.ch/svn/root/trunk@41145 27541ba8-7e3a-0410-8455-c3a389f83636
---
 gui/guibuilder/src/TGuiBldDragManager.cxx |  9 ++-
 gui/guibuilder/src/TGuiBldNameFrame.cxx   | 95 +++++++++++------------
 2 files changed, 49 insertions(+), 55 deletions(-)

diff --git a/gui/guibuilder/src/TGuiBldDragManager.cxx b/gui/guibuilder/src/TGuiBldDragManager.cxx
index 64154b6b651..74f83c5ebc0 100644
--- a/gui/guibuilder/src/TGuiBldDragManager.cxx
+++ b/gui/guibuilder/src/TGuiBldDragManager.cxx
@@ -3265,11 +3265,12 @@ void TGuiBldDragManager::CloneEditable()
    }
 
    TString tmpfile = gSystem->TempDirectory();
-   tmpfile = gSystem->ConcatFileName(tmpfile.Data(), TString::Format("tmp%d.C",
+   char *s = gSystem->ConcatFileName(tmpfile.Data(), TString::Format("tmp%d.C",
                                      gRandom->Integer(100)));
-   Save(tmpfile.Data());
-   gROOT->Macro(tmpfile.Data());
-   gSystem->Unlink(tmpfile.Data());
+   Save(s);
+   gROOT->Macro(s);
+   gSystem->Unlink(s);
+   delete [] s;
 
    if (fClient->GetRoot()->InheritsFrom(TGFrame::Class())) {
       TGFrame *f = (TGFrame *)fClient->GetRoot();
diff --git a/gui/guibuilder/src/TGuiBldNameFrame.cxx b/gui/guibuilder/src/TGuiBldNameFrame.cxx
index 82b8cc1e038..4c061ed7d15 100644
--- a/gui/guibuilder/src/TGuiBldNameFrame.cxx
+++ b/gui/guibuilder/src/TGuiBldNameFrame.cxx
@@ -145,17 +145,15 @@ void TGuiBldNameFrame::ChangeSelected(TGFrame *frame)
    TGCompositeFrame *main = GetMdi(frame);
 
    if (main) {
-      if ((!fListTree) || (!fListTree->GetFirstItem()))
+      if (!fListTree->GetFirstItem())
          MapItems(main);
       else if ((fListTree->GetFirstItem()->GetUserData()) != main) {
          //different MDI
-         if (fListTree) {
-            //clear the list tree displayed
-            while (fListTree->GetFirstItem()) {
-               fListTree->DeleteItem(fListTree->GetFirstItem());
-            }
-            MapItems(main);
+         //clear the list tree displayed
+         while (fListTree->GetFirstItem()) {
+            fListTree->DeleteItem(fListTree->GetFirstItem());
          }
+         MapItems(main);
       }
       else // check if new items added or old ones reparented -> update tree
          CheckItems(main);
@@ -175,10 +173,8 @@ void TGuiBldNameFrame::ChangeSelected(TGFrame *frame)
    fClient->NeedRedraw(fListTree, kTRUE);
    fClient->NeedRedraw(fCanvas, kTRUE);
    DoRedraw();
-
 }
 
-
 //______________________________________________________________________________
 void TGuiBldNameFrame::UpdateName()
 {
@@ -209,17 +205,15 @@ void TGuiBldNameFrame::UpdateName()
       frame->SetName(ch);
    }
 
-   if (fListTree) {
-      //clear the list tree displayed
-      while (fListTree->GetFirstItem()) {
-         fListTree->DeleteItem(fListTree->GetFirstItem());
-      }
+   //clear the list tree displayed
+   while (fListTree->GetFirstItem()) {
+      fListTree->DeleteItem(fListTree->GetFirstItem());
    }
 
    TGCompositeFrame *main = GetMdi(frame);
    MapItems(main);
 
-   if (fListTree) fClient->NeedRedraw(fListTree, kTRUE);
+   fClient->NeedRedraw(fListTree, kTRUE);
    fClient->NeedRedraw(fFrameName);
    DoRedraw();
 }
@@ -299,40 +293,37 @@ Bool_t TGuiBldNameFrame::CheckItems(TGCompositeFrame *main)
 
    TList *list = main->GetList(); //list of all elements in the frame
 
-   if (fListTree) {
-
-      TGFrameElement *el = 0;
-      TGListTreeItem *item = 0;
-      TIter next(list);
-      TGFrame *f = 0;
-      TGListTreeItem *par = 0;
-
-      while ((el = (TGFrameElement *) next())) {
-         if (el && (el->fFrame)) {
-            item = fListTree->FindItemByObj(fListTree->GetFirstItem(),
-                                            el->fFrame);
-            if (!item) {
-               f = (TGFrame*)el->fFrame->GetParent();
-               if (f) {
-                  par = fListTree->FindItemByObj(fListTree->GetFirstItem(), f);
-                  if (par)
-                     fListTree->AddItem(par, el->fFrame->GetName(), el->fFrame);
-               }
-               //return kTRUE; //selected item not found = is newly created
-            }
-            else if (item->GetParent() && item->GetParent()->GetUserData() !=
-                     el->fFrame->GetParent()) {
-               f = (TGFrame*)el->fFrame->GetParent();
-               if (f) {
-                  par = fListTree->FindItemByObj(fListTree->GetFirstItem(), f);
-                  if (par)
-                     fListTree->Reparent(item, par);
-               }
-               //return kTRUE; //parent of the item changed
+   TGFrameElement *el = 0;
+   TGListTreeItem *item = 0;
+   TIter next(list);
+   TGFrame *f = 0;
+   TGListTreeItem *par = 0;
+
+   while ((el = (TGFrameElement *) next())) {
+      if (el && (el->fFrame)) {
+         item = fListTree->FindItemByObj(fListTree->GetFirstItem(),
+                                         el->fFrame);
+         if (!item) {
+            f = (TGFrame*)el->fFrame->GetParent();
+            if (f) {
+               par = fListTree->FindItemByObj(fListTree->GetFirstItem(), f);
+               if (par)
+                  fListTree->AddItem(par, el->fFrame->GetName(), el->fFrame);
             }
-            if (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) {
-               CheckItems((TGCompositeFrame*)el->fFrame);
+            //return kTRUE; //selected item not found = is newly created
+         }
+         else if (item->GetParent() && item->GetParent()->GetUserData() !=
+                  el->fFrame->GetParent()) {
+            f = (TGFrame*)el->fFrame->GetParent();
+            if (f) {
+               par = fListTree->FindItemByObj(fListTree->GetFirstItem(), f);
+               if (par)
+                  fListTree->Reparent(item, par);
             }
+            //return kTRUE; //parent of the item changed
+         }
+         if (el->fFrame->InheritsFrom(TGCompositeFrame::Class())) {
+            CheckItems((TGCompositeFrame*)el->fFrame);
          }
       }
    }
@@ -380,10 +371,12 @@ void TGuiBldNameFrame::SelectFrameByItem(TGListTreeItem* item, Int_t)
    // When list tree item is clicked, frame with that name is selected.
 
    TGFrame *frame = (TGFrame*)item->GetUserData();
-   ((TGFrame*)frame->GetParent())->SetEditable(kTRUE);
-   fManager->SelectFrame(frame);
-   frame->SetEditable(kTRUE);
-   fClient->NeedRedraw(frame);
+   if (frame) {
+      ((TGFrame*)frame->GetParent())->SetEditable(kTRUE);
+      fManager->SelectFrame(frame);
+      frame->SetEditable(kTRUE);
+      fClient->NeedRedraw(frame);
+   }
 }
 
 
-- 
GitLab