dynamic_cast should be checked
From: Erik Hovland <erik@hovland.org>
---
mythtv/libs/libmythui/mythuibutton.cpp | 16 ++++++++++++----
mythtv/libs/libmythui/mythuibuttonlist.cpp | 12 ++++++++----
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/mythtv/libs/libmythui/mythuibutton.cpp b/mythtv/libs/libmythui/mythuibutton.cpp
index 56f304d..725b291 100644
a
|
b
|
|
1 | | #include <iostream> |
2 | | using namespace std; |
3 | | |
4 | 1 | #include "mythuibutton.h" |
5 | 2 | #include "mythmainwindow.h" |
| 3 | #include "mythverbose.h" |
| 4 | #include <iostream> |
| 5 | using namespace std; |
6 | 6 | |
7 | 7 | MythUIButton::MythUIButton(MythUIType *parent, const QString &name, bool doInit) |
8 | 8 | : MythUIType(parent, name) |
… |
… |
void MythUIButton::CopyFrom(MythUIType *base) |
386 | 386 | MythUIButton *button = dynamic_cast<MythUIButton *>(base); |
387 | 387 | if (!button) |
388 | 388 | { |
389 | | cerr << "ERROR, bad parsing" << endl; |
| 389 | VERBOSE(VB_IMPORTANT, |
| 390 | "MythUIButton::CopyFrom: Dynamic cast of base failed"); |
390 | 391 | return; |
391 | 392 | } |
392 | 393 | |
… |
… |
void MythUIButton::CopyFrom(MythUIType *base) |
410 | 411 | (GetChild("buttonimage")); |
411 | 412 | m_ArrowImage = dynamic_cast<MythUIImage *> |
412 | 413 | (GetChild("arrowimage")); |
| 414 | if (m_BackgroundImage || !m_CheckImage || !m_Text || !m_ButtonImage || |
| 415 | !m_ArrowImage) |
| 416 | { |
| 417 | VERBOSE(VB_IMPORTANT, |
| 418 | "MythUIButton::CopyFrom: Dynamic cast of a child failed"); |
| 419 | return; |
| 420 | } |
413 | 421 | |
414 | 422 | m_CheckImage->SetVisible(false); |
415 | 423 | m_ButtonImage->SetVisible(false); |
diff --git a/mythtv/libs/libmythui/mythuibuttonlist.cpp b/mythtv/libs/libmythui/mythuibuttonlist.cpp
index c9dfcfe..078b09d 100644
a
|
b
|
void MythUIButtonList::Init() |
620 | 620 | MythUIStateType *buttontemplate = dynamic_cast<MythUIStateType *> |
621 | 621 | (GetChild("buttonitem")); |
622 | 622 | |
623 | | buttontemplate->SetVisible(false); |
624 | | |
625 | | QRect buttonItemArea = buttontemplate->GetArea(); |
| 623 | QRect buttonItemArea; |
| 624 | if (buttontemplate) |
| 625 | { |
| 626 | buttontemplate->SetVisible(false); |
| 627 | buttonItemArea = buttontemplate->GetArea(); |
| 628 | } |
626 | 629 | |
627 | 630 | if (buttonItemArea.height() > 0) |
628 | 631 | m_itemHeight = buttonItemArea.height(); |
… |
… |
void MythUIButtonList::Init() |
648 | 651 | { |
649 | 652 | QString name = QString("buttonlist button %1").arg(i); |
650 | 653 | MythUIStateType *button = new MythUIStateType(this, name); |
651 | | button->CopyFrom(buttontemplate); |
| 654 | if (buttontemplate) |
| 655 | button->CopyFrom(buttontemplate); |
652 | 656 | |
653 | 657 | if (col > m_columns) |
654 | 658 | { |