Skip to content

Commit

Permalink
Fix a few 'Unchecked dynamic_cast' warnings from Coverity in libmythu…
Browse files Browse the repository at this point in the history
…i. Most of these could safely be switched to static_cast because they are not expected to fail.
  • Loading branch information
stuartm committed May 10, 2012
1 parent 97bbc95 commit 943bfe9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2081,7 +2081,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
d->gestureTimer->stop(); d->gestureTimer->stop();
d->gestureTimer->start(GESTURE_TIMEOUT); d->gestureTimer->start(GESTURE_TIMEOUT);


d->gesture.record(dynamic_cast<QMouseEvent*>(e)->pos()); d->gesture.record(static_cast<QMouseEvent*>(e)->pos());
return true; return true;
} }
break; break;
Expand All @@ -2090,7 +2090,7 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
{ {
ResetIdleTimer(); ResetIdleTimer();
ShowMouseCursor(true); ShowMouseCursor(true);
QWheelEvent* qmw = dynamic_cast<QWheelEvent*>(e); QWheelEvent* qmw = static_cast<QWheelEvent*>(e);
int delta = qmw->delta(); int delta = qmw->delta();
if (delta>0) if (delta>0)
{ {
Expand Down
12 changes: 9 additions & 3 deletions mythtv/libs/libmythui/mythuibuttonlist.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ bool MythUIButtonList::DistributeRow(int &first_button, int &last_button,
realButton = m_ButtonList[buttonIdx]; realButton = m_ButtonList[buttonIdx];
buttonstate = dynamic_cast<MythUIGroup *> buttonstate = dynamic_cast<MythUIGroup *>
(realButton->GetCurrentState()); (realButton->GetCurrentState());
if (!buttonstate)
break;
width = minButtonWidth(buttonstate->GetArea()); width = minButtonWidth(buttonstate->GetArea());


if ((*col_widths)[col_idx] < width) if ((*col_widths)[col_idx] < width)
Expand Down Expand Up @@ -1182,6 +1184,9 @@ bool MythUIButtonList::DistributeButtons(void)
realButton = m_ButtonList[buttonIdx]; realButton = m_ButtonList[buttonIdx];
buttonstate = dynamic_cast<MythUIGroup *> buttonstate = dynamic_cast<MythUIGroup *>
(realButton->GetCurrentState()); (realButton->GetCurrentState());
if (!buttonstate)
break; // Not continue

MythRect area = buttonstate->GetArea(); MythRect area = buttonstate->GetArea();


// Center button within width of column // Center button within width of column
Expand Down Expand Up @@ -1876,7 +1881,7 @@ int MythUIButtonList::PageDown(void)
buttonstate = dynamic_cast<MythUIGroup *> buttonstate = dynamic_cast<MythUIGroup *>
(realButton->GetCurrentState()); (realButton->GetCurrentState());


if (buttonstate == NULL) if (!buttonstate)
{ {
LOG(VB_GENERAL, LOG_ERR, LOG(VB_GENERAL, LOG_ERR,
"PageDown: Failed to query buttonlist state"); "PageDown: Failed to query buttonlist state");
Expand All @@ -1890,7 +1895,8 @@ int MythUIButtonList::PageDown(void)
buttonItem->SetToRealButton(realButton, false); buttonItem->SetToRealButton(realButton, false);
buttonstate = dynamic_cast<MythUIGroup *> buttonstate = dynamic_cast<MythUIGroup *>
(realButton->GetCurrentState()); (realButton->GetCurrentState());
total += m_itemHorizSpacing + buttonstate->GetArea().height(); if (buttonstate)
total += m_itemHorizSpacing + buttonstate->GetArea().height();
} }


return num_items - 1; return num_items - 1;
Expand Down Expand Up @@ -2503,7 +2509,7 @@ void MythUIButtonList::customEvent(QEvent *event)
if (event->type() == NextButtonListPageEvent::kEventType) if (event->type() == NextButtonListPageEvent::kEventType)
{ {
NextButtonListPageEvent *npe = NextButtonListPageEvent *npe =
dynamic_cast<NextButtonListPageEvent*>(event); static_cast<NextButtonListPageEvent*>(event);
int cur = npe->m_start; int cur = npe->m_start;
for (; cur < npe->m_start + npe->m_pageSize && cur < GetCount(); ++cur) for (; cur < npe->m_start + npe->m_pageSize && cur < GetCount(); ++cur)
{ {
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuiimage.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ void MythUIImage::customEvent(QEvent *event)
QString filename; QString filename;
bool aborted; bool aborted;


ImageLoadEvent *le = dynamic_cast<ImageLoadEvent *>(event); ImageLoadEvent *le = static_cast<ImageLoadEvent *>(event);


if (le->GetParent() != this) if (le->GetParent() != this)
return; return;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuistatetype.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void MythUIStateType::RecalculateArea(bool recurse)
{ {
if (objectName().startsWith("buttonlist button")) if (objectName().startsWith("buttonlist button"))
{ {
MythUIButtonList *list = dynamic_cast<MythUIButtonList *>(m_Parent); MythUIButtonList *list = static_cast<MythUIButtonList *>(m_Parent);
m_ParentArea = list->GetButtonArea(); m_ParentArea = list->GetButtonArea();
} }
else else
Expand Down

0 comments on commit 943bfe9

Please sign in to comment.