Ticket #5502: libs_libmythui-check-dyn_cast.patch

File libs_libmythui-check-dyn_cast.patch, 2.7 KB (added by Erik Hovland <erik@…>, 11 years ago)

check dynamic_cast in libmythui

  • mythtv/libs/libmythui/mythuibutton.cpp

    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 
    41#include "mythuibutton.h"
    52#include "mythmainwindow.h"
     3#include "mythverbose.h"
     4#include <iostream>
     5using namespace std;
    66
    77MythUIButton::MythUIButton(MythUIType *parent, const QString &name, bool doInit)
    88            : MythUIType(parent, name)
    void MythUIButton::CopyFrom(MythUIType *base) 
    386386    MythUIButton *button = dynamic_cast<MythUIButton *>(base);
    387387    if (!button)
    388388    {
    389         cerr << "ERROR, bad parsing" << endl;
     389        VERBOSE(VB_IMPORTANT,
     390                "MythUIButton::CopyFrom: Dynamic cast of base failed");
    390391        return;
    391392    }
    392393
    void MythUIButton::CopyFrom(MythUIType *base) 
    410411                    (GetChild("buttonimage"));
    411412    m_ArrowImage = dynamic_cast<MythUIImage *>
    412413                    (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    }
    413421
    414422    m_CheckImage->SetVisible(false);
    415423    m_ButtonImage->SetVisible(false);
  • mythtv/libs/libmythui/mythuibuttonlist.cpp

    diff --git a/mythtv/libs/libmythui/mythuibuttonlist.cpp b/mythtv/libs/libmythui/mythuibuttonlist.cpp
    index c9dfcfe..078b09d 100644
    a b void MythUIButtonList::Init() 
    620620    MythUIStateType *buttontemplate = dynamic_cast<MythUIStateType *>
    621621                                                (GetChild("buttonitem"));
    622622
    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    }
    626629
    627630    if (buttonItemArea.height() > 0)
    628631        m_itemHeight = buttonItemArea.height();
    void MythUIButtonList::Init() 
    648651    {
    649652        QString name = QString("buttonlist button %1").arg(i);
    650653        MythUIStateType *button = new MythUIStateType(this, name);
    651         button->CopyFrom(buttontemplate);
     654        if (buttontemplate)
     655            button->CopyFrom(buttontemplate);
    652656
    653657        if (col > m_columns)
    654658        {