[haiku-commits] haiku: hrev47516 - src/kits/tracker

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 18 Jul 2014 17:00:06 +0200 (CEST)

hrev47516 adds 3 changesets to branch 'master'
old head: 61dec7d2ec230a5ec8351fa171e3b0af5ccab36e
new head: b992df8968fcc9e83f0e247966571196ce5c90c9
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=b992df8+%5E61dec7d

----------------------------------------------------------------------------

6527415: Tracker: obligatory round of style fixes
  
  * Explicit NULL checks
  * whitespace
  * single line if gets no {}'s
  *

bb804d0: Tracker: Make sure count > 0
  
  ... in a more stylish way, no negative counts allowed.

b992df8: Tracker: Don't crash clicking Open with... menu item
  
  This bug was introduced in hrev47498
  
  The reason Tracker crashed was because OpenWithContainerWindow
  had a NULL TargetModel() which we were trying to dereference.
  
  Fix this by creating an empty model in OpenWithContainerWindow. Add an
  ASSERT to check that the TargetModel() is not NULL in the future.
  
  Another way to fix this bug would have been to check that TargetModel() wasn't
  NULL each time before we use it. I didn't go with that solution because we
  assume TargetModel() is not NULL in a lot of places so it would be a lot of 
work
  to check them all. I think it's better to give OpenWithContainerWindow a dummy
  model even though it doesn't make sense for it to have one just so that we 
don't
  crash when we try to dereference the pointer.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 14 insertions(+), 13 deletions(-)
src/kits/tracker/ContainerWindow.cpp | 21 +++++++++++----------
src/kits/tracker/OpenWithWindow.cpp  |  4 ++--
src/kits/tracker/Tracker.cpp         |  2 +-

############################################################################

Commit:      6527415d5a7134839f2ed65459a63e3c310dce9c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6527415
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jul 18 14:42:06 2014 UTC

Tracker: obligatory round of style fixes

* Explicit NULL checks
* whitespace
* single line if gets no {}'s
*

----------------------------------------------------------------------------

diff --git a/src/kits/tracker/ContainerWindow.cpp 
b/src/kits/tracker/ContainerWindow.cpp
index 639853b..ee99ab0 100644
--- a/src/kits/tracker/ContainerWindow.cpp
+++ b/src/kits/tracker/ContainerWindow.cpp
@@ -2674,12 +2674,11 @@ BContainerWindow::ShowContextMenu(BPoint loc, const 
entry_ref* ref, BView*)
        PoseView()->ConvertToScreen(&global);
        PoseView()->CommitActivePose();
 
-       if (ref) {
+       if (ref != NULL) {
                // clicked on a pose, show file or volume context menu
                Model model(ref);
 
                if (model.IsTrash()) {
-
                        if (fTrashContextMenu->Window() || Dragging())
                                return;
 
@@ -2693,7 +2692,6 @@ BContainerWindow::ShowContextMenu(BPoint loc, const 
entry_ref* ref, BView*)
                        SetupNavigationMenu(ref, fTrashContextMenu);
                        fTrashContextMenu->Go(global, true, true, true);
                } else {
-
                        bool showAsVolume = false;
                        bool filePanel = PoseView()->IsFilePanel();
 
@@ -3072,9 +3070,9 @@ BContainerWindow::BuildMimeTypeList(BObjectList<BString> 
&mimeTypes)
                        if (pose->TargetModel()->IsSymLink()) {
                                Model* resolved = new Model(
                                        pose->TargetModel()->EntryRef(), true, 
true);
-                               if (resolved->InitCheck() == B_OK) {
+                               if (resolved->InitCheck() == B_OK)
                                        AddMimeTypeString(mimeTypes, resolved);
-                               }
+
                                delete resolved;
                        }
                }
@@ -3096,7 +3094,7 @@ BContainerWindow::BuildAddOnMenu(BMenu* menu)
                return;
 
        menu = item->Submenu();
-       if (!menu)
+       if (menu == NULL)
                return;
 
        menu->SetFont(be_plain_font);
diff --git a/src/kits/tracker/OpenWithWindow.cpp 
b/src/kits/tracker/OpenWithWindow.cpp
index 2a86933..1ce74a3 100644
--- a/src/kits/tracker/OpenWithWindow.cpp
+++ b/src/kits/tracker/OpenWithWindow.cpp
@@ -184,7 +184,7 @@ OpenWithContainerWindow::NewPoseView(Model*, BRect rect, 
uint32)
 OpenWithPoseView*
 OpenWithContainerWindow::PoseView() const
 {
-       ASSERT(dynamic_cast<OpenWithPoseView*>(fPoseView));
+       ASSERT(dynamic_cast<OpenWithPoseView*>(fPoseView) != NULL);
 
        return static_cast<OpenWithPoseView*>(fPoseView);
 }
diff --git a/src/kits/tracker/Tracker.cpp b/src/kits/tracker/Tracker.cpp
index 9914b23..ef650dd 100644
--- a/src/kits/tracker/Tracker.cpp
+++ b/src/kits/tracker/Tracker.cpp
@@ -1030,7 +1030,7 @@ TTracker::OpenContainerWindow(Model* model, BMessage* 
originalRefsList,
                if (originalRefsList == NULL) {
                        // when passing just a single model, stuff it's entry 
in a single
                        // element list anyway
-                       ASSERT(model);
+                       ASSERT(model != NULL);
                        refList = new BMessage;
                        refList->AddRef("refs", model->EntryRef());
                        delete model;

############################################################################

Commit:      bb804d092e1aeb1a9245f1a90beb22950b936925
URL:         http://cgit.haiku-os.org/haiku/commit/?id=bb804d0
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jul 18 14:43:54 2014 UTC

Tracker: Make sure count > 0

... in a more stylish way, no negative counts allowed.

----------------------------------------------------------------------------

diff --git a/src/kits/tracker/ContainerWindow.cpp 
b/src/kits/tracker/ContainerWindow.cpp
index ee99ab0..0626900 100644
--- a/src/kits/tracker/ContainerWindow.cpp
+++ b/src/kits/tracker/ContainerWindow.cpp
@@ -3058,7 +3058,7 @@ void
 BContainerWindow::BuildMimeTypeList(BObjectList<BString> &mimeTypes)
 {
        int32 count = PoseView()->SelectionList()->CountItems();
-       if (!count) {
+       if (count > 0) {
                // just add the type of the current directory
                AddMimeTypeString(mimeTypes, TargetModel());
        } else {
@@ -3127,7 +3127,7 @@ BContainerWindow::BuildAddOnMenu(BMenu* menu)
        for (int32 index = 0; index < count; index++)
                menu->AddItem(primaryList.ItemAt(index));
 
-       if (count != 0)
+       if (count > 0)
                menu->AddSeparatorItem();
 
        count = secondaryList.CountItems();

############################################################################

Revision:    hrev47516
Commit:      b992df8968fcc9e83f0e247966571196ce5c90c9
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b992df8
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Fri Jul 18 14:58:30 2014 UTC

Tracker: Don't crash clicking Open with... menu item

This bug was introduced in hrev47498

The reason Tracker crashed was because OpenWithContainerWindow
had a NULL TargetModel() which we were trying to dereference.

Fix this by creating an empty model in OpenWithContainerWindow. Add an
ASSERT to check that the TargetModel() is not NULL in the future.

Another way to fix this bug would have been to check that TargetModel() wasn't
NULL each time before we use it. I didn't go with that solution because we
assume TargetModel() is not NULL in a lot of places so it would be a lot of work
to check them all. I think it's better to give OpenWithContainerWindow a dummy
model even though it doesn't make sense for it to have one just so that we don't
crash when we try to dereference the pointer.

----------------------------------------------------------------------------

diff --git a/src/kits/tracker/ContainerWindow.cpp 
b/src/kits/tracker/ContainerWindow.cpp
index 0626900..3502398 100644
--- a/src/kits/tracker/ContainerWindow.cpp
+++ b/src/kits/tracker/ContainerWindow.cpp
@@ -2906,6 +2906,9 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
        // since we check view mode before display, this should be a radio
        // mode menu
 
+       Model* targetModel = TargetModel();
+       ASSERT(targetModel != NULL);
+
        bool needSeparator = true;
        if (IsTrash()) {
                menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
@@ -2913,7 +2916,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
        } else if (IsPrintersDir()) {
                menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" 
B_UTF8_ELLIPSIS),
                        new BMessage(kAddPrinter), 'N'));
-       } else if (InTrash() || TargetModel()->IsRoot()) {
+       } else if (InTrash() || targetModel->IsRoot()) {
                needSeparator = false;
        } else {
                TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(),
@@ -2945,7 +2948,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
                        new BMessage(kOpenParentDir), B_UP_ARROW));
        }
 
-       if (TargetModel()->IsRoot()) {
+       if (targetModel->IsRoot()) {
                menu->AddSeparatorItem();
                menu->AddItem(new MountMenu(B_TRANSLATE("Mount")));
        }
diff --git a/src/kits/tracker/OpenWithWindow.cpp 
b/src/kits/tracker/OpenWithWindow.cpp
index 1ce74a3..615a6e9 100644
--- a/src/kits/tracker/OpenWithWindow.cpp
+++ b/src/kits/tracker/OpenWithWindow.cpp
@@ -540,7 +540,7 @@ OpenWithContainerWindow::SetCanOpen(bool on)
 
 OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask)
        :
-       BPoseView(0, frame, kListMode, resizeMask),
+       BPoseView(new Model(), frame, kListMode, resizeMask),
        fHaveCommonPreferredApp(false),
        fIterator(NULL)
 {


Other related posts: