VirtualBox

Changeset 21404 in vbox for trunk


Ignore:
Timestamp:
Jul 8, 2009 3:19:42 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49780
Message:

IPRT, Main: make ministring throw std::bad_alloc on allocation failure; remove isEmpty() and isNull(), change Main code to using length() instead; second try

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/ministring_cpp.h

    r21394 r21404  
    3535#include <iprt/string.h>
    3636
     37#include <new>
     38
    3739/**
    3840 *  "ministring" is a small C++ string class that does not depend on anything
     
    125127        {
    126128            m_psz = (char*)RTMemRealloc(m_psz, cb);
     129#ifdef RT_EXCEPTIONS_ENABLED
     130            if (!m_psz)
     131                throw std::bad_alloc();
     132#endif
    127133            m_cbAllocated = cb;
    128134        }
     
    255261    {
    256262        return length() == 0;
    257     }
    258 
    259     /**
    260      * Returns true if no memory is currently allocated.
    261      * @return
    262      */
    263     bool isNull() const
    264     {
    265         return m_psz == NULL;
    266263    }
    267264
     
    349346            m_cbAllocated = m_cbLength + 1;
    350347            m_psz = (char*)RTMemAlloc(m_cbAllocated);
     348#ifdef RT_EXCEPTIONS_ENABLED
     349            if (!m_psz)
     350                throw std::bad_alloc();
     351#endif
    351352            memcpy(m_psz, s.m_psz, m_cbAllocated);      // include 0 terminator
    352353        }
     
    374375            m_cbAllocated = m_cbLength + 1;
    375376            m_psz = (char*)RTMemAlloc(m_cbAllocated);
     377#ifdef RT_EXCEPTIONS_ENABLED
     378            if (!m_psz)
     379                throw std::bad_alloc();
     380#endif
    376381            memcpy(m_psz, pcsz, m_cbAllocated);      // include 0 terminator
    377382        }
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestProp.cpp

    r21394 r21404  
    167167    {
    168168        HRESULT rc = S_OK;
    169         Utf8Str utf8Name (name);
     169        Utf8Str utf8Name(name);
    170170        Guid uuid(machineId);
    171         if (utf8Name.isNull())
    172             rc = E_OUTOFMEMORY;
    173171        if (   SUCCEEDED (rc)
    174172            && uuid == mUuid
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r21394 r21404  
    14751475
    14761476            /* Audio */
    1477             if (!vsysThis.strSoundCardType.isNull())
     1477            if (!vsysThis.strSoundCardType.isEmpty())
    14781478                /* Currently we set the AC97 always.
    14791479                   @todo: figure out the hardware which could be possible */
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r21394 r21404  
    10841084    for (unsigned i = 0; i < 10 && (VERR_BUFFER_OVERFLOW == vrc); ++i)
    10851085    {
    1086         Utf8Buf.reserve(cchBuf + 1024);
    1087         if (Utf8Buf.isNull())
     1086        try
     1087        {
     1088            Utf8Buf.reserve(cchBuf + 1024);
     1089        }
     1090        catch(...)
     1091        {
    10881092            return E_OUTOFMEMORY;
     1093        }
    10891094        parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
    10901095        parm[1].u.pointer.addr = Utf8Buf.mutableRaw();
     
    38713876    using namespace guestProp;
    38723877
    3873     VBOXHGCMSVCPARM parm[4];
    3874     Utf8Str Utf8Name = aName;
    3875     AssertReturn(!Utf8Name.isNull(), E_OUTOFMEMORY);
    3876     char pszBuffer[MAX_VALUE_LEN + MAX_FLAGS_LEN];
    3877 
    3878     parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
    3879     parm[0].u.pointer.addr = (void*)Utf8Name.c_str();
    3880     /* The + 1 is the null terminator */
    3881     parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1;
    3882     parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
    3883     parm[1].u.pointer.addr = pszBuffer;
    3884     parm[1].u.pointer.size = sizeof(pszBuffer);
    3885     int vrc = mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", GET_PROP_HOST,
    3886                                      4, &parm[0]);
    3887     /* The returned string should never be able to be greater than our buffer */
    3888     AssertLogRel (vrc != VERR_BUFFER_OVERFLOW);
    3889     AssertLogRel (RT_FAILURE(vrc) || VBOX_HGCM_SVC_PARM_64BIT == parm[2].type);
    3890     if (RT_SUCCESS (vrc) || (VERR_NOT_FOUND == vrc))
    3891     {
    3892         rc = S_OK;
    3893         if (vrc != VERR_NOT_FOUND)
    3894         {
    3895             Utf8Str strBuffer(pszBuffer);
    3896             strBuffer.cloneTo(aValue);
    3897 
    3898             *aTimestamp = parm[2].u.uint64;
    3899 
    3900             size_t iFlags = strBuffer.length() + 1;
    3901             Utf8Str(pszBuffer + iFlags).cloneTo(aFlags);
     3878    try
     3879    {
     3880        VBOXHGCMSVCPARM parm[4];
     3881        Utf8Str Utf8Name = aName;
     3882        char pszBuffer[MAX_VALUE_LEN + MAX_FLAGS_LEN];
     3883
     3884        parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
     3885        parm[0].u.pointer.addr = (void*)Utf8Name.c_str();
     3886        /* The + 1 is the null terminator */
     3887        parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1;
     3888        parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
     3889        parm[1].u.pointer.addr = pszBuffer;
     3890        parm[1].u.pointer.size = sizeof(pszBuffer);
     3891        int vrc = mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", GET_PROP_HOST,
     3892                                        4, &parm[0]);
     3893        /* The returned string should never be able to be greater than our buffer */
     3894        AssertLogRel (vrc != VERR_BUFFER_OVERFLOW);
     3895        AssertLogRel (RT_FAILURE(vrc) || VBOX_HGCM_SVC_PARM_64BIT == parm[2].type);
     3896        if (RT_SUCCESS (vrc) || (VERR_NOT_FOUND == vrc))
     3897        {
     3898            rc = S_OK;
     3899            if (vrc != VERR_NOT_FOUND)
     3900            {
     3901                Utf8Str strBuffer(pszBuffer);
     3902                strBuffer.cloneTo(aValue);
     3903
     3904                *aTimestamp = parm[2].u.uint64;
     3905
     3906                size_t iFlags = strBuffer.length() + 1;
     3907                Utf8Str(pszBuffer + iFlags).cloneTo(aFlags);
     3908            }
     3909            else
     3910                aValue = NULL;
    39023911        }
    39033912        else
    3904             aValue = NULL;
    3905     }
    3906     else
    3907         rc = setError (E_UNEXPECTED,
    3908             tr ("The service call failed with the error %Rrc"), vrc);
     3913            rc = setError (E_UNEXPECTED,
     3914                tr ("The service call failed with the error %Rrc"), vrc);
     3915    }
     3916    catch(std::bad_alloc &e)
     3917    {
     3918        rc = E_OUTOFMEMORY;
     3919    }
    39093920    return rc;
    39103921#endif /* else !defined (VBOX_WITH_GUEST_PROPS) */
     
    43924403
    43934404    /* make sure the Logs folder exists */
    4394     Assert (!logDir.isEmpty());
     4405    Assert(logDir.length());
    43954406    if (!RTDirExists (logDir))
    43964407        RTDirCreateFullPath (logDir, 0777);
     
    61916202
    61926203    /* append to the existing error message if any */
    6193     if (!task->mErrorMsg.isEmpty())
     6204    if (task->mErrorMsg.length())
    61946205        task->mErrorMsg = Utf8StrFmt ("%s.\n%N (%Rrc)", task->mErrorMsg.raw(),
    61956206                                      pszFormat, &va2, rc, rc);
     
    66666677
    66676678                /* Load saved state? */
    6668                 if (!task->mSavedStateFile.isEmpty())
     6679                if (task->mSavedStateFile.length())
    66696680                {
    66706681                    LogFlowFunc (("Restoring saved state from '%s'...\n",
     
    67496760             * this function is not updated.
    67506761             */
    6751             if (task->mErrorMsg.isNull())
     6762            if (!task->mErrorMsg.length())
    67526763            {
    67536764                /* If the error message is not set but we've got a failure,
     
    70957106    AssertReturn (task.get(), VERR_INVALID_PARAMETER);
    70967107
    7097     Assert (!task->mSavedStateFile.isNull());
    7098     Assert (!task->mProgress.isNull());
     7108    Assert(task->mSavedStateFile.length());
     7109    Assert(!task->mProgress.isNull());
    70997110
    71007111    const ComObjPtr <Console> &that = task->mConsole;
     
    72527263    else
    72537264    {
    7254         if (!errMsg.isNull())
    7255             task->mProgress->notifyComplete (rc,
    7256                 COM_IIDOF(IConsole), Console::getComponentName(), errMsg);
     7265        if (errMsg.length())
     7266            task->mProgress->notifyComplete(rc,
     7267                                            COM_IIDOF(IConsole),
     7268                                            Console::getComponentName(),
     7269                                            errMsg);
    72577270        else
    72587271            task->mProgress->notifyComplete (rc);
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r21394 r21404  
    18011801     * Guest property service
    18021802     */
     1803    try
    18031804    {
    18041805        /* Load the service */
     
    18441845                timestamps.push_back(timestampsOut[i]);
    18451846                utf8Flags.push_back(Bstr(flagsOut[i]));
    1846 #if 0 /** @todo r=bird: Who is gonna catch this? Why does it trigger now? */
    1847                 if (   utf8Names.back().isNull()
    1848                     || utf8Values.back().isNull()
    1849                     || utf8Flags.back().isNull()
    1850                    )
    1851                     throw std::bad_alloc();
    1852 #endif
    18531847            }
    18541848            for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
     
    18891883            Log(("Set VBoxGuestPropSvc property store\n"));
    18901884        }
     1885    }
     1886    catch(std::bad_alloc &e)
     1887    {
     1888        return VERR_NO_MEMORY;
    18911889    }
    18921890#endif /* VBOX_WITH_GUEST_PROPS defined */
  • trunk/src/VBox/Main/DHCPServerRunner.cpp

    r21394 r21404  
    9797    for (unsigned i = 0; i < DHCPCFG_NOTOPT_MAXVAL; i++)
    9898    {
    99         if (!mOptions[i].isNull())
     99        if (mOptions[i].length())
    100100        {
    101101            const ARGDEF * pArgDef = getArgDef((DHCPCFG)i);
    102             args[index++] = pArgDef->Name;
    103             if (!mOptions[i].isEmpty())
    104             {
    105                 args[index++] = mOptions[i].raw();
    106             }
     102            args[index++] = pArgDef->Name;      // e.g. "--network"
     103            args[index++] = mOptions[i].raw();  // value
    107104        }
    108105    }
  • trunk/src/VBox/Main/MachineImpl.cpp

    r21394 r21404  
    27802780        Utf8Str logFolder;
    27812781        getLogFolder (logFolder);
    2782         Assert (!logFolder.isEmpty());
    2783         if (RTDirExists (logFolder))
     2782        Assert(logFolder.length());
     2783        if (RTDirExists(logFolder))
    27842784        {
    27852785            /* Delete all VBox.log[.N] files from the Logs folder
     
    28052805         * there (we don't check for errors because the user might have
    28062806         * some private files there that we don't want to delete) */
    2807         Utf8Str snapshotFolder = mUserData->mSnapshotFolderFull;
    2808         Assert (!snapshotFolder.isEmpty());
    2809         if (RTDirExists (snapshotFolder))
    2810             RTDirRemove (snapshotFolder);
     2807        Utf8Str snapshotFolder(mUserData->mSnapshotFolderFull);
     2808        Assert(snapshotFolder.length());
     2809        if (RTDirExists(snapshotFolder))
     2810            RTDirRemove(snapshotFolder);
    28112811
    28122812        /* delete the directory that contains the settings file, but only
     
    30563056}
    30573057
    3058 STDMETHODIMP Machine::SetGuestProperty (IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags)
     3058STDMETHODIMP Machine::SetGuestProperty(IN_BSTR aName,
     3059                                       IN_BSTR aValue,
     3060                                       IN_BSTR aFlags)
    30593061{
    30603062#if !defined (VBOX_WITH_GUEST_PROPS)
     
    30683070        return E_INVALIDARG;
    30693071
    3070     Utf8Str utf8Name (aName);
    3071     Utf8Str utf8Flags (aFlags);
    3072     Utf8Str utf8Patterns (mHWData->mGuestPropertyNotificationPatterns);
    3073     if (   utf8Name.isNull()
    3074         || ((aFlags != NULL) && utf8Flags.isNull())
    3075         || utf8Patterns.isNull()
    3076        )
    3077         return E_OUTOFMEMORY;
    3078     bool matchAll = false;
    3079     if (0 == utf8Patterns.length())
    3080         matchAll = true;
    3081 
    3082     uint32_t fFlags = NILFLAG;
    3083     if ((aFlags != NULL) && RT_FAILURE (validateFlags (utf8Flags.raw(), &fFlags))
    3084        )
    3085         return setError (E_INVALIDARG, tr ("Invalid flag values: '%ls'"),
    3086                 aFlags);
    3087 
    3088     AutoCaller autoCaller (this);
    3089     CheckComRCReturnRC (autoCaller.rc());
    3090 
    3091     AutoWriteLock alock (this);
    3092 
    3093     HRESULT rc = checkStateDependency (MutableStateDep);
    3094     CheckComRCReturnRC (rc);
    3095 
    3096     rc = S_OK;
    3097 
    3098     if (!mHWData->mPropertyServiceActive)
    3099     {
    3100         bool found = false;
    3101         HWData::GuestProperty property;
    3102         property.mFlags = NILFLAG;
    3103         if (fFlags & TRANSIENT)
    3104             rc = setError (VBOX_E_INVALID_OBJECT_STATE,
    3105                 tr ("Cannot set a transient property when the "
    3106                     "machine is not running"));
    3107         if (SUCCEEDED (rc))
    3108         {
    3109             for (HWData::GuestPropertyList::iterator it =
    3110                     mHWData->mGuestProperties.begin();
    3111                  it != mHWData->mGuestProperties.end(); ++ it)
    3112                 if (it->mName == aName)
     3072    HRESULT rc = S_OK;
     3073
     3074    try
     3075    {
     3076        Utf8Str utf8Name(aName);
     3077        Utf8Str utf8Flags(aFlags);
     3078        Utf8Str utf8Patterns(mHWData->mGuestPropertyNotificationPatterns);
     3079
     3080        bool matchAll = false;
     3081        if (utf8Patterns.isEmpty())
     3082            matchAll = true;
     3083
     3084        uint32_t fFlags = NILFLAG;
     3085        if (    (aFlags != NULL)
     3086             && RT_FAILURE (validateFlags (utf8Flags.raw(), &fFlags))
     3087           )
     3088            return setError(E_INVALIDARG,
     3089                            tr("Invalid flag values: '%ls'"),
     3090                            aFlags);
     3091
     3092        AutoCaller autoCaller(this);
     3093        CheckComRCReturnRC(autoCaller.rc());
     3094
     3095        AutoWriteLock alock(this);
     3096
     3097        rc = checkStateDependency(MutableStateDep);
     3098        CheckComRCReturnRC (rc);
     3099
     3100        rc = S_OK;
     3101
     3102        if (!mHWData->mPropertyServiceActive)
     3103        {
     3104            bool found = false;
     3105            HWData::GuestProperty property;
     3106            property.mFlags = NILFLAG;
     3107            if (fFlags & TRANSIENT)
     3108                rc = setError(VBOX_E_INVALID_OBJECT_STATE,
     3109                              tr("Cannot set a transient property when the machine is not running"));
     3110
     3111            if (SUCCEEDED (rc))
     3112            {
     3113                for (HWData::GuestPropertyList::iterator it =
     3114                        mHWData->mGuestProperties.begin();
     3115                    it != mHWData->mGuestProperties.end(); ++ it)
     3116                    if (it->mName == aName)
     3117                    {
     3118                        property = *it;
     3119                        if (it->mFlags & (RDONLYHOST))
     3120                            rc = setError (E_ACCESSDENIED,
     3121                                tr ("The property '%ls' cannot be changed by the host"),
     3122                                aName);
     3123                        else
     3124                        {
     3125                            mHWData.backup();
     3126                            /* The backup() operation invalidates our iterator, so
     3127                            * get a new one. */
     3128                            for (it = mHWData->mGuestProperties.begin();
     3129                                it->mName != aName; ++ it)
     3130                                ;
     3131                            mHWData->mGuestProperties.erase (it);
     3132                        }
     3133                        found = true;
     3134                        break;
     3135                    }
     3136            }
     3137            if (found && SUCCEEDED (rc))
     3138            {
     3139                if (*aValue)
    31133140                {
    3114                     property = *it;
    3115                     if (it->mFlags & (RDONLYHOST))
    3116                         rc = setError (E_ACCESSDENIED,
    3117                             tr ("The property '%ls' cannot be changed by the host"),
    3118                             aName);
    3119                     else
    3120                     {
    3121                         mHWData.backup();
    3122                         /* The backup() operation invalidates our iterator, so
    3123                          * get a new one. */
    3124                         for (it = mHWData->mGuestProperties.begin();
    3125                             it->mName != aName; ++ it)
    3126                             ;
    3127                         mHWData->mGuestProperties.erase (it);
    3128                     }
    3129                     found = true;
    3130                     break;
     3141                    RTTIMESPEC time;
     3142                    property.mValue = aValue;
     3143                    property.mTimestamp = RTTimeSpecGetNano (RTTimeNow (&time));
     3144                    if (aFlags != NULL)
     3145                        property.mFlags = fFlags;
     3146                    mHWData->mGuestProperties.push_back (property);
    31313147                }
    3132         }
    3133         if (found && SUCCEEDED (rc))
    3134         {
    3135             if (*aValue)
     3148            }
     3149            else if (SUCCEEDED (rc) && *aValue)
    31363150            {
    31373151                RTTIMESPEC time;
     3152                mHWData.backup();
     3153                property.mName = aName;
    31383154                property.mValue = aValue;
    31393155                property.mTimestamp = RTTimeSpecGetNano (RTTimeNow (&time));
    3140                 if (aFlags != NULL)
    3141                     property.mFlags = fFlags;
     3156                property.mFlags = fFlags;
    31423157                mHWData->mGuestProperties.push_back (property);
    31433158            }
    3144         }
    3145         else if (SUCCEEDED (rc) && *aValue)
    3146         {
    3147             RTTIMESPEC time;
    3148             mHWData.backup();
    3149             property.mName = aName;
    3150             property.mValue = aValue;
    3151             property.mTimestamp = RTTimeSpecGetNano (RTTimeNow (&time));
    3152             property.mFlags = fFlags;
    3153             mHWData->mGuestProperties.push_back (property);
    3154         }
    3155         if (   SUCCEEDED (rc)
    3156             && (   matchAll
    3157                 || RTStrSimplePatternMultiMatch (utf8Patterns.raw(), RTSTR_MAX,
    3158                                                 utf8Name.raw(), RTSTR_MAX, NULL)
    3159               )
    3160           )
    3161             mParent->onGuestPropertyChange (mData->mUuid, aName, aValue, aFlags);
    3162     }
    3163     else
    3164     {
    3165         ComPtr <IInternalSessionControl> directControl =
    3166             mData->mSession.mDirectControl;
    3167 
    3168         /* just be on the safe side when calling another process */
    3169         alock.leave();
    3170 
    3171         BSTR dummy = NULL;
    3172         ULONG64 dummy64;
    3173         if (!directControl)
    3174             rc = E_FAIL;
     3159            if (   SUCCEEDED (rc)
     3160                && (   matchAll
     3161                    || RTStrSimplePatternMultiMatch (utf8Patterns.raw(), RTSTR_MAX,
     3162                                                    utf8Name.raw(), RTSTR_MAX, NULL)
     3163                )
     3164            )
     3165                mParent->onGuestPropertyChange (mData->mUuid, aName, aValue, aFlags);
     3166        }
    31753167        else
    3176             rc = directControl->AccessGuestProperty (aName, aValue, aFlags,
    3177                                                      true /* isSetter */,
    3178                                                      &dummy, &dummy64, &dummy);
    3179     }
     3168        {
     3169            ComPtr <IInternalSessionControl> directControl =
     3170                mData->mSession.mDirectControl;
     3171
     3172            /* just be on the safe side when calling another process */
     3173            alock.leave();
     3174
     3175            BSTR dummy = NULL;
     3176            ULONG64 dummy64;
     3177            if (!directControl)
     3178                rc = E_FAIL;
     3179            else
     3180                rc = directControl->AccessGuestProperty(aName, aValue, aFlags,
     3181                                                        true /* isSetter */,
     3182                                                        &dummy, &dummy64, &dummy);
     3183        }
     3184    }
     3185    catch (std::bad_alloc &e)
     3186    {
     3187        rc = E_OUTOFMEMORY;
     3188    }
     3189
    31803190    return rc;
    31813191#endif /* else !defined (VBOX_WITH_GUEST_PROPS) */
     
    54015411#ifdef VBOX_WITH_GUEST_PROPS
    54025412    /* Guest properties (optional) */
     5413    try
    54035414    {
    54045415        using namespace guestProp;
     
    54225433                /* property flags (optional, defaults to empty) */
    54235434                Bstr flags = (*it).stringValue ("flags");
    5424                 Utf8Str utf8Flags (flags);
    5425                 if (utf8Flags.isNull ())
    5426                     return E_OUTOFMEMORY;
     5435                Utf8Str utf8Flags(flags);
    54275436                validateFlags (utf8Flags.raw(), &fFlags);
    54285437                HWData::GuestProperty property = { name, value, timestamp, fFlags };
     
    54425451        if (mHWData->mGuestPropertyNotificationPatterns.isNull ())
    54435452            return E_OUTOFMEMORY;
     5453    }
     5454    catch(std::bad_alloc &e)
     5455    {
     5456        return E_OUTOFMEMORY;
    54445457    }
    54455458#endif /* VBOX_WITH_GUEST_PROPS defined */
     
    96169629        return E_POINTER;  /* aValue can be NULL to indicate deletion */
    96179630
    9618     Utf8Str utf8Name (aName);
    9619     Utf8Str utf8Flags (aFlags);
    9620     Utf8Str utf8Patterns (mHWData->mGuestPropertyNotificationPatterns);
    9621     if (   utf8Name.isNull()
    9622         || ((aFlags != NULL) && utf8Flags.isNull())
    9623         || utf8Patterns.isNull()
    9624        )
     9631    try
     9632    {
     9633        Utf8Str utf8Name(aName);
     9634        Utf8Str utf8Flags(aFlags);
     9635        Utf8Str utf8Patterns(mHWData->mGuestPropertyNotificationPatterns);
     9636
     9637        uint32_t fFlags = NILFLAG;
     9638        if ((aFlags != NULL) && RT_FAILURE (validateFlags (utf8Flags.raw(), &fFlags)))
     9639            return E_INVALIDARG;
     9640
     9641        bool matchAll = false;
     9642        if (utf8Patterns.isEmpty())
     9643            matchAll = true;
     9644
     9645        AutoCaller autoCaller (this);
     9646        CheckComRCReturnRC (autoCaller.rc());
     9647
     9648        AutoWriteLock alock (this);
     9649
     9650        HRESULT rc = checkStateDependency (MutableStateDep);
     9651        CheckComRCReturnRC (rc);
     9652
     9653        mHWData.backup();
     9654        for (HWData::GuestPropertyList::iterator iter = mHWData->mGuestProperties.begin();
     9655            iter != mHWData->mGuestProperties.end(); ++iter)
     9656            if (aName == iter->mName)
     9657            {
     9658                mHWData->mGuestProperties.erase (iter);
     9659                break;
     9660            }
     9661        if (aValue != NULL)
     9662        {
     9663            HWData::GuestProperty property = { aName, aValue, aTimestamp, fFlags };
     9664            mHWData->mGuestProperties.push_back (property);
     9665        }
     9666
     9667        /* send a callback notification if appropriate */
     9668        alock.leave();
     9669        if (   matchAll
     9670            || RTStrSimplePatternMultiMatch (utf8Patterns.raw(), RTSTR_MAX,
     9671                                            utf8Name.raw(), RTSTR_MAX, NULL)
     9672        )
     9673            mParent->onGuestPropertyChange (mData->mUuid, aName, aValue, aFlags);
     9674    }
     9675    catch(std::bad_alloc &e)
     9676    {
    96259677        return E_OUTOFMEMORY;
    9626 
    9627     uint32_t fFlags = NILFLAG;
    9628     if ((aFlags != NULL) && RT_FAILURE (validateFlags (utf8Flags.raw(), &fFlags)))
    9629         return E_INVALIDARG;
    9630 
    9631     bool matchAll = false;
    9632     if (utf8Patterns.length() == 0)
    9633         matchAll = true;
    9634 
    9635     AutoCaller autoCaller (this);
    9636     CheckComRCReturnRC (autoCaller.rc());
    9637 
    9638     AutoWriteLock alock (this);
    9639 
    9640     HRESULT rc = checkStateDependency (MutableStateDep);
    9641     CheckComRCReturnRC (rc);
    9642 
    9643     mHWData.backup();
    9644     for (HWData::GuestPropertyList::iterator iter = mHWData->mGuestProperties.begin();
    9645          iter != mHWData->mGuestProperties.end(); ++iter)
    9646         if (aName == iter->mName)
    9647         {
    9648             mHWData->mGuestProperties.erase (iter);
    9649             break;
    9650         }
    9651     if (aValue != NULL)
    9652     {
    9653         HWData::GuestProperty property = { aName, aValue, aTimestamp, fFlags };
    9654         mHWData->mGuestProperties.push_back (property);
    9655     }
    9656 
    9657     /* send a callback notification if appropriate */
    9658     alock.leave();
    9659     if (   matchAll
    9660         || RTStrSimplePatternMultiMatch (utf8Patterns.raw(), RTSTR_MAX,
    9661                                          utf8Name.raw(), RTSTR_MAX, NULL)
    9662        )
    9663         mParent->onGuestPropertyChange (mData->mUuid, aName, aValue, aFlags);
    9664 
     9678    }
    96659679    return S_OK;
    96669680#else
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r21394 r21404  
    412412
    413413    /* state file may be NULL (for offline snapshots) */
    414     if (    !path.isEmpty()
     414    if (    path.length()
    415415         && RTPathStartsWith(path, aOldPath)
    416416       )
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r21394 r21404  
    34813481    AutoReadLock hardDiskLock (aHardDisk);
    34823482
    3483     Utf8Str conflict;
    3484     HRESULT rc = checkMediaForConflicts2 (aHardDisk->id(),
    3485                                           aHardDisk->locationFull(),
    3486                                           conflict);
     3483    Utf8Str strConflict;
     3484    HRESULT rc = checkMediaForConflicts2(aHardDisk->id(),
     3485                                         aHardDisk->locationFull(),
     3486                                         strConflict);
    34873487    CheckComRCReturnRC (rc);
    34883488
    3489     if (!conflict.isNull())
    3490     {
    3491         return setError (E_INVALIDARG,
    3492             tr ("Cannot register the hard disk '%ls' with UUID {%RTuuid} "
    3493                 "because a %s already exists in the media registry ('%ls')"),
    3494             aHardDisk->locationFull().raw(), aHardDisk->id().raw(),
    3495             conflict.raw(), mData.mCfgFile.mName.raw());
     3489    if (strConflict.length())
     3490    {
     3491        return setError(E_INVALIDARG,
     3492                        tr("Cannot register the hard disk '%ls' with UUID {%RTuuid} because a %s already exists in the media registry ('%ls')"),
     3493                        aHardDisk->locationFull().raw(),
     3494                        aHardDisk->id().raw(),
     3495                        strConflict.raw(),
     3496                        mData.mCfgFile.mName.raw());
    34963497    }
    34973498
     
    35983599    AutoReadLock imageLock (aImage);
    35993600
    3600     Utf8Str conflict;
    3601     HRESULT rc = checkMediaForConflicts2 (aImage->id(), aImage->locationFull(),
    3602                                           conflict);
     3601    Utf8Str strConflict;
     3602    HRESULT rc = checkMediaForConflicts2(aImage->id(),
     3603                                         aImage->locationFull(),
     3604                                         strConflict);
    36033605    CheckComRCReturnRC (rc);
    36043606
    3605     if (!conflict.isNull())
    3606     {
    3607         return setError (VBOX_E_INVALID_OBJECT_STATE,
    3608             tr ("Cannot register the CD/DVD image '%ls' with UUID {%RTuuid} "
    3609                 "because a %s already exists in the media registry ('%ls')"),
    3610             aImage->locationFull().raw(), aImage->id().raw(),
    3611             conflict.raw(), mData.mCfgFile.mName.raw());
     3607    if (strConflict.length())
     3608    {
     3609        return setError(VBOX_E_INVALID_OBJECT_STATE,
     3610                        tr("Cannot register the CD/DVD image '%ls' with UUID {%RTuuid} because a %s already exists in the media registry ('%ls')"),
     3611                        aImage->locationFull().raw(),
     3612                        aImage->id().raw(),
     3613                        strConflict.raw(),
     3614                        mData.mCfgFile.mName.raw());
    36123615    }
    36133616
     
    36993702    AutoReadLock imageLock (aImage);
    37003703
    3701     Utf8Str conflict;
    3702     HRESULT rc = checkMediaForConflicts2 (aImage->id(), aImage->locationFull(),
    3703                                           conflict);
     3704    Utf8Str strConflict;
     3705    HRESULT rc = checkMediaForConflicts2(aImage->id(),
     3706                                         aImage->locationFull(),
     3707                                         strConflict);
    37043708    CheckComRCReturnRC (rc);
    37053709
    3706     if (!conflict.isNull())
    3707     {
    3708         return setError (VBOX_E_INVALID_OBJECT_STATE,
    3709             tr ("Cannot register the floppy image '%ls' with UUID {%RTuuid} "
    3710                 "because a %s already exists in the media registry ('%ls')"),
    3711             aImage->locationFull().raw(), aImage->id().raw(),
    3712             conflict.raw(), mData.mCfgFile.mName.raw());
     3710    if (strConflict.length())
     3711    {
     3712        return setError(VBOX_E_INVALID_OBJECT_STATE,
     3713                        tr("Cannot register the floppy image '%ls' with UUID {%RTuuid} because a %s already exists in the media registry ('%ls')"),
     3714                        aImage->locationFull().raw(),
     3715                        aImage->id().raw(),
     3716                        strConflict.raw(),
     3717                        mData.mCfgFile.mName.raw());
    37133718    }
    37143719
     
    39373942        {
    39383943            *aFormatVersion = aTree.oldVersion();
    3939             if (aFormatVersion->isNull())
     3944            if (!aFormatVersion->length())
    39403945                *aFormatVersion = VBOX_XML_VERSION_FULL;
    39413946        }
  • trunk/src/VBox/Main/glue/string.cpp

    r21394 r21404  
    139139Utf8Str& Utf8Str::toLower()
    140140{
    141     if (!isEmpty())
     141    if (length())
    142142        ::RTStrToLower(m_psz);
    143143    return *this;
     
    146146Utf8Str& Utf8Str::toUpper()
    147147{
    148     if (!isEmpty())
     148    if (length())
    149149        ::RTStrToUpper(m_psz);
    150150    return *this;
  • trunk/src/VBox/Main/win/svchlp.cpp

    r21081 r21404  
    179179
    180180    /* write -1 for NULL strings */
    181     if (aVal.isNull())
     181    if (aVal.isEmpty())
    182182        return write ((size_t) ~0);
    183183
  • trunk/src/VBox/Runtime/testcase/tstUtf8.cpp

    r21394 r21404  
    987987
    988988    copy1 = NULL;
    989     CHECK( (copy1.isNull()) );
     989    CHECK( (copy1.length() == 0) );
    990990
    991991    copy1 = "";
    992     CHECK( (copy1.isEmpty()) );
     992    CHECK( (copy1.length() == 0) );
    993993
    994994    CHECK( (ministring("abc") < ministring("def")) );
Note: See TracChangeset for help on using the changeset viewer.

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