VirtualBox

Changeset 85284 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Jul 12, 2020 3:11:52 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139261
Message:

Main/MediumImpl.cpp: Signed/unsigned conversion issues, a whole bunch which was mixing VBox status codes and COM statues via setErrorVrc in the moveTo() code. Changed i_resize to take an uint64_t size rather than LONG64, and made resize() fail on negative or zero size. bugref:9790

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r82968 r85284  
    2626
    2727#include "AutoCaller.h"
     28#include "Global.h"
    2829#include "LoggingNew.h"
    2930#include "ThreadTask.h"
     
    12711272        {
    12721273            // Otherwise use the old VirtualBox "make absolute path" logic:
    1273             rc = m->pVirtualBox->i_calculateFullPath(data.strLocation, strFull);
    1274             if (FAILED(rc)) return rc;
     1274            int vrc = m->pVirtualBox->i_calculateFullPath(data.strLocation, strFull);
     1275            if (RT_FAILURE(vrc))
     1276                return Global::vboxStatusCodeToCOM(vrc);
    12751277        }
    12761278    }
     
    17021704    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    17031705
    1704     *aSize = m->size;
     1706    *aSize = (LONG64)m->size;
    17051707
    17061708    return S_OK;
     
    19471949    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    19481950
    1949     *aLogicalSize = m->logicalSize;
     1951    *aLogicalSize = (LONG64)m->logicalSize;
    19501952
    19511953    return S_OK;
     
    25892591
    25902592        /* setup task object to carry out the operation asynchronously */
    2591         pTask = new Medium::CreateBaseTask(this, pProgress, aLogicalSize,
     2593        pTask = new Medium::CreateBaseTask(this, pProgress, (uint64_t)aLogicalSize,
    25922594                                           (MediumVariant_T)mediumVariantFlags);
    25932595        rc = pTask->rc();
     
    27842786                            ComPtr<IProgress> &aProgress)
    27852787{
    2786      int rc = S_OK;
    2787 
    2788      rc =  cloneTo(aTarget, aVariant, NULL, aProgress);
    2789      return rc;
     2788     return cloneTo(aTarget, aVariant, NULL, aProgress);
    27902789}
    27912790
     
    29792978            if (aLocation.isEmpty())
    29802979            {
    2981                 rc = setError(VERR_PATH_ZERO_LENGTH,
    2982                            tr("Medium '%s' can't be moved. Destination path is empty."),
    2983                            i_getLocationFull().c_str());
     2980                rc = setErrorVrc(VERR_PATH_ZERO_LENGTH,
     2981                                 tr("Medium '%s' can't be moved. Destination path is empty."),
     2982                                 i_getLocationFull().c_str());
    29842983                throw rc;
    29852984            }
     
    30463045                                break;
    30473046                            default:
    3048                                 rc = setError(VERR_NOT_A_FILE, /** @todo r=bird: Mixing status codes again. */
    3049                                        tr("Medium '%s' has RAW type. \"Move\" operation isn't supported for this type."),
    3050                                        i_getLocationFull().c_str());
     3047                                rc = setErrorVrc(VERR_NOT_A_FILE, /** @todo r=bird: Mixing status codes again. */
     3048                                                 tr("Medium '%s' has RAW type. \"Move\" operation isn't supported for this type."),
     3049                                                 i_getLocationFull().c_str());
    30513050                                throw rc;
    30523051                        }
     
    30763075            if (!i_isMediumFormatFile())
    30773076            {
    3078                 rc = setError(VERR_NOT_A_FILE,
    3079                               tr("Medium '%s' isn't a file object. \"Move\" operation isn't supported."),
    3080                               i_getLocationFull().c_str());
     3077                rc = setErrorVrc(VERR_NOT_A_FILE,
     3078                                 tr("Medium '%s' isn't a file object. \"Move\" operation isn't supported."),
     3079                                 i_getLocationFull().c_str());
    30813080                throw rc;
    30823081            }
     
    30983097            if (FAILED(rc))
    30993098            {
    3100                 rc = setError(VERR_NO_CHANGE,
    3101                            tr("Medium '%s' is already in the correct location"),
    3102                            i_getLocationFull().c_str());
     3099                rc = setErrorVrc(VERR_NO_CHANGE,
     3100                                 tr("Medium '%s' is already in the correct location"),
     3101                                 i_getLocationFull().c_str());
    31033102                throw rc;
    31043103            }
     
    31413140                if (ses)
    31423141                {
    3143                     rc = setError(VERR_VM_UNEXPECTED_VM_STATE,
     3142                    rc = setError(VBOX_E_INVALID_VM_STATE,
    31443143                                  tr("At least the VM '%s' to whom this medium '%s' attached has currently an opened session. Stop all VMs before relocating this medium"),
    31453144                                  id.toString().c_str(),
     
    32993298                        alock.acquire();
    33003299
    3301                         rc = setError(VERR_VM_UNEXPECTED_VM_STATE,
     3300                        rc = setError(VBOX_E_INVALID_VM_STATE,
    33023301                                      tr("At least the VM '%s' to whom this medium '%s' attached has currently an opened session. Stop all VMs before set location for this medium"),
    33033302                                      id.toString().c_str(),
     
    34063405                       ComPtr<IProgress> &aProgress)
    34073406{
     3407    CheckComArgExpr(aLogicalSize, aLogicalSize > 0);
    34083408    HRESULT rc = S_OK;
    34093409    ComObjPtr<Progress> pProgress;
     
    34533453
    34543454    if (SUCCEEDED(rc))
    3455         rc = i_resize(aLogicalSize, pMediumLockList, &pProgress, false /* aWait */, true /* aNotify */);
     3455        rc = i_resize((uint64_t)aLogicalSize, pMediumLockList, &pProgress, false /* aWait */, true /* aNotify */);
    34563456
    34573457    if (SUCCEEDED(rc))
     
    50665066    /* m->variant is const, no need to lock */
    50675067    ULONG mediumVariantFlags = (ULONG)m->variant;
    5068     mediumVariantFlags &= ~(MediumVariant_Fixed | MediumVariant_VmdkStreamOptimized);
     5068    mediumVariantFlags &= ~(ULONG)(MediumVariant_Fixed | MediumVariant_VmdkStreamOptimized);
    50695069    mediumVariantFlags |= MediumVariant_Diff;
    50705070    return (MediumVariant_T)mediumVariantFlags;
     
    61866186 */
    61876187
    6188 HRESULT Medium::i_resize(LONG64 aLogicalSize,
     6188HRESULT Medium::i_resize(uint64_t aLogicalSize,
    61896189                         MediumLockList *aMediumLockList,
    61906190                         ComObjPtr<Progress> *aProgress,
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