diff options
Diffstat (limited to 'src/VBox/Runtime/common/misc/sg.cpp')
-rw-r--r-- | src/VBox/Runtime/common/misc/sg.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/VBox/Runtime/common/misc/sg.cpp b/src/VBox/Runtime/common/misc/sg.cpp index 08ef8b632..b679b9de6 100644 --- a/src/VBox/Runtime/common/misc/sg.cpp +++ b/src/VBox/Runtime/common/misc/sg.cpp @@ -1,4 +1,4 @@ -/* $Id: sg.cpp 36312 2011-03-18 12:59:15Z vboxsync $ */ +/* $Id: sg.cpp $ */ /** @file * IPRT - S/G buffer handling. */ @@ -35,8 +35,16 @@ static void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData) { - size_t cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft); - void *pvBuf = pSgBuf->pvSegCur; + size_t cbData; + void *pvBuf; + + /* Check that the S/G buffer has memory left. */ + if (RT_UNLIKELY( pSgBuf->idxSeg == pSgBuf->cSegs + && !pSgBuf->cbSegLeft)) + { + *pcbData = 0; + return NULL; + } AssertReleaseMsg( pSgBuf->cbSegLeft <= 5 * _1M && (uintptr_t)pSgBuf->pvSegCur >= (uintptr_t)pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg @@ -45,6 +53,8 @@ static void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData) pSgBuf->idxSeg, pSgBuf->cSegs, pSgBuf->pvSegCur, pSgBuf->cbSegLeft, pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg, pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg)); + cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft); + pvBuf = pSgBuf->pvSegCur; pSgBuf->cbSegLeft -= cbData; /* Advance to the next segment if required. */ @@ -52,12 +62,7 @@ static void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData) { pSgBuf->idxSeg++; - if (RT_UNLIKELY(pSgBuf->idxSeg == pSgBuf->cSegs)) - { - pSgBuf->cbSegLeft = 0; - pSgBuf->pvSegCur = NULL; - } - else + if (pSgBuf->idxSeg < pSgBuf->cSegs) { pSgBuf->pvSegCur = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg; pSgBuf->cbSegLeft = pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg; |