VirtualBox

Changeset 75984 in vbox for trunk/src


Ignore:
Timestamp:
Dec 5, 2018 5:29:39 PM (6 years ago)
Author:
vboxsync
Message:

GuestProperties: Use RTCString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r75981 r75984  
    4848#include <iprt/cpp/autores.h>
    4949#include <iprt/cpp/utils.h>
     50#include <iprt/cpp/ministring.h>
    5051#include <iprt/err.h>
    5152#include <iprt/mem.h>
     
    5758#include <VBox/version.h>
    5859
    59 #include <string>
    6060#include <list>
    6161
     
    7373    RTSTRSPACECORE mStrCore;
    7474    /** The name of the property */
    75     std::string mName;
     75    RTCString mName;
    7676    /** The property value */
    77     std::string mValue;
     77    RTCString mValue;
    7878    /** The timestamp of the property */
    7979    uint64_t mTimestamp;
     
    8787    }
    8888    /** Constructor with const char * */
    89     Property(const char *pcszName, const char *pcszValue,
    90              uint64_t u64Timestamp, uint32_t u32Flags)
    91         : mName(pcszName), mValue(pcszValue), mTimestamp(u64Timestamp),
    92           mFlags(u32Flags)
     89    Property(const char *pcszName, const char *pcszValue, uint64_t nsTimestamp, uint32_t u32Flags)
     90        : mName(pcszName)
     91        , mValue(pcszValue)
     92        , mTimestamp(nsTimestamp)
     93        , mFlags(u32Flags)
    9394    {
    9495        RT_ZERO(mStrCore);
     
    9697    }
    9798    /** Constructor with std::string */
    98     Property(std::string name, std::string value, uint64_t u64Timestamp,
    99              uint32_t u32Flags)
    100         : mName(name), mValue(value), mTimestamp(u64Timestamp),
    101           mFlags(u32Flags)
     99    Property(RTCString const &rName, RTCString const &rValue, uint64_t nsTimestamp, uint32_t fFlags)
     100        : mName(rName)
     101        , mValue(rValue)
     102        , mTimestamp(nsTimestamp)
     103        , mFlags(fFlags)
    102104    {}
    103105
     
    129131    bool isNull()
    130132    {
    131         return mName.empty();
     133        return mName.isEmpty();
    132134    }
    133135};
     
    234236        for (;    it != mGuestNotifications.end()
    235237               && it->mTimestamp != u64Timestamp; ++it)
    236             {}
     238        { /*nothing*/ }
    237239        if (it == mGuestNotifications.end())  /* Not found */
    238240            it = mGuestNotifications.begin();
     
    668670            /* Check that the buffer is big enough */
    669671            size_t const cbFlags  = strlen(szFlags) + 1;
    670             size_t const cbValue  = pProp->mValue.size() + 1;
     672            size_t const cbValue  = pProp->mValue.length() + 1;
    671673            size_t const cbNeeded = cbValue + cbFlags;
    672674            HGCMSvcSetU32(&paParms[3], (uint32_t)cbNeeded);
     
    10851087
    10861088    /* Format the data to write to the buffer. */
    1087     std::string buffer;
    1088     uint64_t u64Timestamp;
    1089     char *pchBuf;
     1089    char    *pchBuf;
    10901090    uint32_t cbBuf;
    1091 
    10921091    int rc = HGCMSvcGetBuf(&paParms[2], (void **)&pchBuf, &cbBuf);
    10931092    if (RT_SUCCESS(rc))
     
    10971096        if (RT_SUCCESS(rc))
    10981097        {
    1099             buffer += prop.mName;
    1100             buffer += '\0';
    1101             buffer += prop.mValue;
    1102             buffer += '\0';
    1103             buffer += szFlags;
    1104             buffer += '\0';
    1105             u64Timestamp = prop.mTimestamp;
    1106 
    1107             /* Write out the data. */
    1108             if (RT_SUCCESS(rc))
     1098            HGCMSvcSetU64(&paParms[1], prop.mTimestamp);
     1099
     1100            size_t const cbFlags  = strlen(szFlags) + 1;
     1101            size_t const cbName   = prop.mName.length() + 1;
     1102            size_t const cbValue  = prop.mValue.length() + 1;
     1103            size_t const cbNeeded = cbName + cbValue + cbFlags;
     1104            HGCMSvcSetU32(&paParms[3], (uint32_t)cbNeeded);
     1105            if (cbNeeded <= cbBuf)
    11091106            {
    1110                 HGCMSvcSetU64(&paParms[1], u64Timestamp);
    1111                 HGCMSvcSetU32(&paParms[3], (uint32_t)buffer.size());
    1112                 if (buffer.size() <= cbBuf)
    1113                     buffer.copy(pchBuf, cbBuf);
    1114                 else
    1115                     rc = VERR_BUFFER_OVERFLOW;
     1107                memcpy(pchBuf, prop.mName.c_str(), cbName);
     1108                pchBuf += cbName;
     1109                memcpy(pchBuf, prop.mValue.c_str(), cbValue);
     1110                pchBuf += cbValue;
     1111                memcpy(pchBuf, szFlags, cbFlags);
    11161112            }
     1113            else
     1114                rc = VERR_BUFFER_OVERFLOW;
    11171115        }
    11181116    }
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