From 2655efc3958f7e000e1a5b3c66c2fb9b469f03ac Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 17 Aug 2010 14:56:51 +0000 Subject: [PATCH] Fixes to Notifications preflet * CID-1501: protect against dynamic_cast potentially returning NULL * additional style fixes * fixed all warnings and enabled -Werror git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38188 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/BuildSetup | 2 +- src/preferences/notifications/IconItem.cpp | 4 +-- src/preferences/notifications/IconRule.cpp | 2 +- src/preferences/notifications/IconRule.h | 2 +- .../notifications/NotificationsView.cpp | 25 +++++++++++-------- src/preferences/notifications/PrefletView.cpp | 6 ++--- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/build/jam/BuildSetup b/build/jam/BuildSetup index b0ffbd6c2d..264cad83f5 100644 --- a/build/jam/BuildSetup +++ b/build/jam/BuildSetup @@ -1406,7 +1406,7 @@ if $(HAIKU_NO_WERROR) != 1 { EnableWerror src preferences media ; EnableWerror src preferences mouse ; EnableWerror src preferences network ; -# EnableWerror src preferences notifications ; + EnableWerror src preferences notifications ; EnableWerror src preferences opengl ; EnableWerror src preferences print ; EnableWerror src preferences screen ; diff --git a/src/preferences/notifications/IconItem.cpp b/src/preferences/notifications/IconItem.cpp index 58f68a6a50..eb2b656591 100644 --- a/src/preferences/notifications/IconItem.cpp +++ b/src/preferences/notifications/IconItem.cpp @@ -17,10 +17,10 @@ const int32 kEdgeOffset = 4; -BIconItem::BIconItem(BView* owner, const char* label, BBitmap* icon) +BIconItem::BIconItem(BView* owner, const char* label, BBitmap* icon) : - fIcon(icon), fLabel(label), + fIcon(icon), fSelected(false), fOwner(owner) { diff --git a/src/preferences/notifications/IconRule.cpp b/src/preferences/notifications/IconRule.cpp index f8912b3847..75b2502cf7 100644 --- a/src/preferences/notifications/IconRule.cpp +++ b/src/preferences/notifications/IconRule.cpp @@ -146,7 +146,7 @@ BIconRule::SetSelectionMessage(BMessage* message) } -int32 +void BIconRule::AddIcon(const char* label, const BBitmap* icon) { BIconItem* item = new BIconItem(this, label, (BBitmap*)icon); diff --git a/src/preferences/notifications/IconRule.h b/src/preferences/notifications/IconRule.h index 854bbc1a12..5939892240 100644 --- a/src/preferences/notifications/IconRule.h +++ b/src/preferences/notifications/IconRule.h @@ -27,7 +27,7 @@ public: BMessage* SelectionMessage() const; void SetSelectionMessage(BMessage* message); - int32 AddIcon(const char* label, const BBitmap* icon); + void AddIcon(const char* label, const BBitmap* icon); void RemoveIconAt(int32 index); void RemoveAllIcons(); diff --git a/src/preferences/notifications/NotificationsView.cpp b/src/preferences/notifications/NotificationsView.cpp index bcde7ce4e4..890437e1e9 100644 --- a/src/preferences/notifications/NotificationsView.cpp +++ b/src/preferences/notifications/NotificationsView.cpp @@ -140,17 +140,22 @@ void NotificationsView::MessageReceived(BMessage* msg) { switch (msg->what) { - case kApplicationSelected: { - BRow *row = fApplications->CurrentSelection(); - if (row == NULL) - return; - BStringField* appname = - dynamic_cast(row->GetField(kAppIndex)); + case kApplicationSelected: + { + BRow* row = fApplications->CurrentSelection(); + if (row == NULL) + return; + BStringField* appName + = dynamic_cast(row->GetField(kAppIndex)); + if (appName == NULL) + break; - appusage_t::iterator it = fAppFilters.find(appname->String()); - if (it != fAppFilters.end()) - _Populate(it->second); - } break; + appusage_t::iterator it = fAppFilters.find(appName->String()); + if (it != fAppFilters.end()) + _Populate(it->second); + + break; + } case kNotificationSelected: break; default: diff --git a/src/preferences/notifications/PrefletView.cpp b/src/preferences/notifications/PrefletView.cpp index 1482502f02..61bf2f62ff 100644 --- a/src/preferences/notifications/PrefletView.cpp +++ b/src/preferences/notifications/PrefletView.cpp @@ -32,9 +32,9 @@ PrefletView::PrefletView(SettingsHost* host) // Page selector fRule = new BIconRule("icon_rule"); fRule->SetSelectionMessage(new BMessage(kPageSelected)); - (void)fRule->AddIcon(_T("General"), NULL); - (void)fRule->AddIcon(_T("Display"), NULL); - //(void)fRule->AddIcon(_T("Notifications"), NULL); + fRule->AddIcon(_T("General"), NULL); + fRule->AddIcon(_T("Display"), NULL); + //fRule->AddIcon(_T("Notifications"), NULL); // View for card layout fPagesView = new BView("pages", B_WILL_DRAW);