VirtualBox

Changeset 60346 in vbox for trunk


Ignore:
Timestamp:
Apr 6, 2016 9:34:14 AM (9 years ago)
Author:
vboxsync
Message:

Runtime/sg.cpp: Allow RTSgBufInit to take NULL and 0 for paSegs and cSegs respectively to indicate an empty buffer

Location:
trunk
Files:
2 edited

Legend:

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

    r59746 r60346  
    8080 * @param   paSegs    Pointer to the start of the segment array.
    8181 * @param   cSegs     Number of segments in the array.
     82 *
     83 * @note paSegs and cSegs can be NULL and 0 respectively to indicate
     84 *       an empty S/G buffer. All operations on the S/G buffer will
     85 *       not do anything in this case.
    8286 */
    8387RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, size_t cSegs);
  • trunk/src/VBox/Runtime/common/misc/sg.cpp

    r59747 r60346  
    8484{
    8585    AssertPtr(pSgBuf);
    86     AssertPtr(paSegs);
    87     Assert(cSegs > 0);
     86    Assert(   (cSegs > 0 && VALID_PTR(paSegs))
     87           || (!cSegs && !paSegs));
    8888    Assert(cSegs < (~(unsigned)0 >> 1));
    8989
     
    9191    pSgBuf->cSegs     = (unsigned)cSegs;
    9292    pSgBuf->idxSeg    = 0;
    93     pSgBuf->pvSegCur  = paSegs[0].pvSeg;
    94     pSgBuf->cbSegLeft = paSegs[0].cbSeg;
     93    if (cSegs && paSegs)
     94    {
     95        pSgBuf->pvSegCur  = paSegs[0].pvSeg;
     96        pSgBuf->cbSegLeft = paSegs[0].cbSeg;
     97    }
     98    else
     99    {
     100        pSgBuf->pvSegCur  = NULL;
     101        pSgBuf->cbSegLeft = 0;
     102    }
    95103}
    96104
     
    100108    AssertPtrReturnVoid(pSgBuf);
    101109
    102     pSgBuf->idxSeg    = 0;
    103     pSgBuf->pvSegCur  = pSgBuf->paSegs[0].pvSeg;
    104     pSgBuf->cbSegLeft = pSgBuf->paSegs[0].cbSeg;
     110    pSgBuf->idxSeg = 0;
     111    if (pSgBuf->cSegs)
     112    {
     113        pSgBuf->pvSegCur  = pSgBuf->paSegs[0].pvSeg;
     114        pSgBuf->cbSegLeft = pSgBuf->paSegs[0].cbSeg;
     115    }
     116    else
     117    {
     118        pSgBuf->pvSegCur  = NULL;
     119        pSgBuf->cbSegLeft = 0;
     120    }
    105121}
    106122
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