VirtualBox

Ignore:
Timestamp:
Dec 6, 2019 11:54:16 PM (5 years ago)
Author:
vboxsync
Message:

clipboard-common.cpp: Use RTMemDup. Some nits. bugref:9437

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp

    r82280 r82477  
    4545{
    4646    AssertPtrReturn(pvData, VERR_INVALID_POINTER);
    47     AssertReturn   (cbData, VERR_INVALID_PARAMETER);
    48 
    49     PSHCLEVENTPAYLOAD pPayload =
    50         (PSHCLEVENTPAYLOAD)RTMemAlloc(sizeof(SHCLEVENTPAYLOAD));
    51     if (!pPayload)
    52         return VERR_NO_MEMORY;
    53 
    54     pPayload->pvData = RTMemAlloc(cbData);
    55     if (pPayload->pvData)
    56     {
    57         memcpy(pPayload->pvData, pvData, cbData);
    58 
    59         pPayload->cbData = cbData;
    60         pPayload->uID    = uID;
    61 
    62         *ppPayload = pPayload;
    63 
    64         return VINF_SUCCESS;
    65     }
    66 
    67     RTMemFree(pPayload);
     47    AssertReturn(cbData > 0, VERR_INVALID_PARAMETER);
     48
     49    PSHCLEVENTPAYLOAD pPayload = (PSHCLEVENTPAYLOAD)RTMemAlloc(sizeof(SHCLEVENTPAYLOAD));
     50    if (pPayload)
     51    {
     52        pPayload->pvData = RTMemDup(pvData, cbData);
     53        if (pPayload->pvData)
     54        {
     55            pPayload->cbData = cbData;
     56            pPayload->uID    = uID;
     57
     58            *ppPayload = pPayload;
     59            return VINF_SUCCESS;
     60        }
     61
     62        RTMemFree(pPayload);
     63    }
    6864    return VERR_NO_MEMORY;
    6965}
     
    8884
    8985    pPayload->cbData = 0;
     86    pPayload->uID = UINT32_MAX;
    9087
    9188    RTMemFree(pPayload);
    92     pPayload = NULL;
    9389}
    9490
     
    148144int ShClEventSourceCreate(PSHCLEVENTSOURCE pSource, SHCLEVENTSOURCEID uID)
    149145{
     146    LogFlowFunc(("pSource=%p, uID=%RU16\n", pSource, uID));
    150147    AssertPtrReturn(pSource, VERR_INVALID_POINTER);
    151 
    152     LogFlowFunc(("pSource=%p, uID=%RU32\n", pSource, uID));
    153 
    154     int rc = VINF_SUCCESS;
    155148
    156149    RTListInit(&pSource->lstEvents);
     
    160153    pSource->uEventIDNext = RTRandU32() % VBOX_SHCL_MAX_EVENTS;
    161154
    162     LogFlowFuncLeaveRC(rc);
    163     return rc;
     155    LogFlowFuncLeaveRC(VINF_SUCCESS);
     156    return VINF_SUCCESS;
    164157}
    165158
     
    178171    ShClEventSourceReset(pSource);
    179172
    180     pSource->uID          = 0;
    181     pSource->uEventIDNext = 0;
     173    pSource->uID          = UINT16_MAX;
     174    pSource->uEventIDNext = UINT32_MAX;
    182175}
    183176
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