VirtualBox

Changeset 85289 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Jul 13, 2020 12:21:34 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139266
Message:

VBox/com/array.h: Probably a good idea to check the com::SafeArray::resize result before copying over new array content in the initFrom() methods and other places. Made the initFrom() methods return HRESULT. Ditto cloneTo(). bugref:9790

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/array.h

    r82968 r85289  
    10121012    }
    10131013
    1014     void cloneTo(SafeArray<T>& aOther) const
     1014    HRESULT cloneTo(SafeArray<T>& aOther) const
    10151015    {
    10161016        aOther.reset(size());
    1017         aOther.initFrom(*this);
     1017        return aOther.initFrom(*this);
    10181018    }
    10191019
     
    10881088    }
    10891089
    1090     inline void initFrom(const com::SafeArray<T> & aRef);
    1091     inline void initFrom(const T* aPtr, size_t aSize);
     1090    inline HRESULT initFrom(const com::SafeArray<T> & aRef);
     1091    inline HRESULT initFrom(const T* aPtr, size_t aSize);
    10921092
    10931093    // Public methods for internal purposes only.
     
    12951295/* Few fast specializations for primitive array types */
    12961296template<>
    1297 inline void com::SafeArray<BYTE>::initFrom(const com::SafeArray<BYTE> & aRef)
     1297inline HRESULT com::SafeArray<BYTE>::initFrom(const com::SafeArray<BYTE> & aRef)
    12981298{
    12991299    size_t sSize = aRef.size();
    1300     resize(sSize);
    1301     ::memcpy(raw(), aRef.raw(), sSize);
     1300    if (resize(sSize))
     1301    {
     1302        ::memcpy(raw(), aRef.raw(), sSize);
     1303        return S_OK;
     1304    }
     1305    return E_OUTOFMEMORY;
    13021306}
    13031307template<>
    1304 inline void com::SafeArray<BYTE>::initFrom(const BYTE* aPtr, size_t aSize)
    1305 {
    1306     resize(aSize);
    1307     ::memcpy(raw(), aPtr, aSize);
     1308inline HRESULT com::SafeArray<BYTE>::initFrom(const BYTE *aPtr, size_t aSize)
     1309{
     1310    if (resize(aSize))
     1311    {
     1312        ::memcpy(raw(), aPtr, aSize);
     1313        return S_OK;
     1314    }
     1315    return E_OUTOFMEMORY;
    13081316}
    13091317
    13101318
    13111319template<>
    1312 inline void com::SafeArray<SHORT>::initFrom(const com::SafeArray<SHORT> & aRef)
     1320inline HRESULT com::SafeArray<SHORT>::initFrom(const com::SafeArray<SHORT> & aRef)
    13131321{
    13141322    size_t sSize = aRef.size();
    1315     resize(sSize);
    1316     ::memcpy(raw(), aRef.raw(), sSize * sizeof(SHORT));
     1323    if (resize(sSize))
     1324    {
     1325        ::memcpy(raw(), aRef.raw(), sSize * sizeof(SHORT));
     1326        return S_OK;
     1327    }
     1328    return E_OUTOFMEMORY;
    13171329}
    13181330template<>
    1319 inline void com::SafeArray<SHORT>::initFrom(const SHORT* aPtr, size_t aSize)
    1320 {
    1321     resize(aSize);
    1322     ::memcpy(raw(), aPtr, aSize * sizeof(SHORT));
     1331inline HRESULT com::SafeArray<SHORT>::initFrom(const SHORT *aPtr, size_t aSize)
     1332{
     1333    if (resize(aSize))
     1334    {
     1335        ::memcpy(raw(), aPtr, aSize * sizeof(SHORT));
     1336        return S_OK;
     1337    }
     1338    return E_OUTOFMEMORY;
    13231339}
    13241340
    13251341template<>
    1326 inline void com::SafeArray<USHORT>::initFrom(const com::SafeArray<USHORT> & aRef)
     1342inline HRESULT com::SafeArray<USHORT>::initFrom(const com::SafeArray<USHORT> & aRef)
    13271343{
    13281344    size_t sSize = aRef.size();
    1329     resize(sSize);
    1330     ::memcpy(raw(), aRef.raw(), sSize * sizeof(USHORT));
     1345    if (resize(sSize))
     1346    {
     1347        ::memcpy(raw(), aRef.raw(), sSize * sizeof(USHORT));
     1348        return S_OK;
     1349    }
     1350    return E_OUTOFMEMORY;
    13311351}
    13321352template<>
    1333 inline void com::SafeArray<USHORT>::initFrom(const USHORT* aPtr, size_t aSize)
    1334 {
    1335     resize(aSize);
    1336     ::memcpy(raw(), aPtr, aSize * sizeof(USHORT));
     1353inline HRESULT com::SafeArray<USHORT>::initFrom(const USHORT *aPtr, size_t aSize)
     1354{
     1355    if (resize(aSize))
     1356    {
     1357        ::memcpy(raw(), aPtr, aSize * sizeof(USHORT));
     1358        return S_OK;
     1359    }
     1360    return E_OUTOFMEMORY;
    13371361}
    13381362
    13391363template<>
    1340 inline void com::SafeArray<LONG>::initFrom(const com::SafeArray<LONG> & aRef)
     1364inline HRESULT com::SafeArray<LONG>::initFrom(const com::SafeArray<LONG> & aRef)
    13411365{
    13421366    size_t sSize = aRef.size();
    1343     resize(sSize);
    1344     ::memcpy(raw(), aRef.raw(), sSize * sizeof(LONG));
     1367    if (resize(sSize))
     1368    {
     1369        ::memcpy(raw(), aRef.raw(), sSize * sizeof(LONG));
     1370        return S_OK;
     1371    }
     1372    return E_OUTOFMEMORY;
    13451373}
    13461374template<>
    1347 inline void com::SafeArray<LONG>::initFrom(const LONG* aPtr, size_t aSize)
    1348 {
    1349     resize(aSize);
    1350     ::memcpy(raw(), aPtr, aSize * sizeof(LONG));
     1375inline HRESULT com::SafeArray<LONG>::initFrom(const LONG *aPtr, size_t aSize)
     1376{
     1377    if (resize(aSize))
     1378    {
     1379        ::memcpy(raw(), aPtr, aSize * sizeof(LONG));
     1380        return S_OK;
     1381    }
     1382    return E_OUTOFMEMORY;
    13511383}
    13521384
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