VirtualBox

Changeset 55983 in vbox


Ignore:
Timestamp:
May 20, 2015 7:26:38 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: UIMedium: Protect wrapper against theoretically possible CMedium glitches.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.cpp

    r55566 r55983  
    175175    {
    176176        /* Refresh medium ID: */
    177         m_strId = m_medium.GetId();
     177        m_strId = normalizedID(m_medium.GetId());
    178178        /* Refresh root medium ID: */
    179179        m_strRootId = m_strId;
     
    231231            CMedium parentMedium = m_medium.GetParent();
    232232            if (!parentMedium.isNull())
    233                 m_strParentId = parentMedium.GetId();
     233                m_strParentId = normalizedID(parentMedium.GetId());
    234234
    235235            /* Only for created and accessible mediums: */
     
    239239                while (!parentMedium.isNull())
    240240                {
    241                     m_strRootId = parentMedium.GetId();
     241                    m_strRootId = normalizedID(parentMedium.GetId());
    242242                    parentMedium = parentMedium.GetParent();
    243243                }
     
    396396        CMedium parentMedium = m_medium.GetParent();
    397397        if (!parentMedium.isNull())
    398             m_strParentId = parentMedium.GetId();
     398            m_strParentId = normalizedID(parentMedium.GetId());
    399399    }
    400400}
     
    529529
    530530/* static */
     531QString UIMedium::normalizedID(const QString &strID)
     532{
     533    AssertMsgReturn(QUuid(strID).toString().remove('{').remove('}') == strID,
     534                    ("CMedium UUID is not valid: '%s'\n", strID.toAscii().constData()),
     535                    nullID());
     536    return strID;
     537}
     538
     539/* static */
    531540bool UIMedium::isMediumAttachedToHiddenMachinesOnly(const UIMedium &medium)
    532541{
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h

    r55557 r55983  
    121121    const CMedium& medium() const { return m_medium; }
    122122
    123     /** Returns @c true if CMedium wrapped by this UIMedium object is a NULL object. */
    124     bool isNull() const { return m_medium.isNull(); }
     123    /** Returns @c true if CMedium wrapped by this UIMedium object has ID == #nullID().
     124      * @note   Also make sure wrapped CMedium is NULL object if his ID == #nullID(). */
     125    bool isNull() const
     126    {
     127        AssertReturn(m_strId != nullID() || m_medium.isNull(), true);
     128        return m_strId == nullID();
     129    }
    125130
    126131    /** Returns the medium state.
     
    285290    static QString nullID();
    286291
     292    /** Returns passed @a strID if it's valid or #nullID() overwise. */
     293    static QString normalizedID(const QString &strID);
     294
    287295    /** Determines if passed @a medium is attached to hidden machines only. */
    288296    static bool isMediumAttachedToHiddenMachinesOnly(const UIMedium &medium);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette