VirtualBox

Changeset 63154 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 8, 2016 12:01:32 PM (8 years ago)
Author:
vboxsync
Message:

Main: More warnings about uninitialized variables (false ones) and size_t vs uint32_t mixup. Some data member renaming too.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r62383 r63154  
    823823#endif
    824824
    825     uint32_t GetOffset() { return m_cbOffset; }
    826 
    827     size_t GetSize() { return m_cbSize; }
     825    uint32_t GetOffset() { return m_offBuffer; }
     826
     827    size_t GetSize() { return m_cbUsed; }
    828828
    829829    int ParseBlock(GuestProcessStreamBlock &streamBlock);
     
    832832
    833833    /** Currently allocated size of internal stream buffer. */
    834     uint32_t m_cbAllocated;
    835     /** Currently used size of allocated internal stream buffer. */
    836     size_t m_cbSize;
    837     /** Current offset within the internal stream buffer. */
    838     uint32_t m_cbOffset;
     834    size_t m_cbAllocated;
     835    /** Currently used size at m_offBuffer. */
     836    size_t m_cbUsed;
     837    /** Current byte offset within the internal stream buffer. */
     838    size_t m_offBuffer;
    839839    /** Internal stream buffer. */
    840840    BYTE *m_pbBuffer;
  • trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp

    r62485 r63154  
    357357GuestProcessStream::GuestProcessStream(void)
    358358    : m_cbAllocated(0),
    359       m_cbSize(0),
    360       m_cbOffset(0),
     359      m_cbUsed(0),
     360      m_offBuffer(0),
    361361      m_pbBuffer(NULL)
    362362{
     
    385385
    386386    /* Rewind the buffer if it's empty. */
    387     size_t     cbInBuf   = m_cbSize - m_cbOffset;
     387    size_t     cbInBuf   = m_cbUsed - m_offBuffer;
    388388    bool const fAddToSet = cbInBuf == 0;
    389389    if (fAddToSet)
    390         m_cbSize = m_cbOffset = 0;
     390        m_cbUsed = m_offBuffer = 0;
    391391
    392392    /* Try and see if we can simply append the data. */
    393     if (cbData + m_cbSize <= m_cbAllocated)
    394     {
    395         memcpy(&m_pbBuffer[m_cbSize], pbData, cbData);
    396         m_cbSize += cbData;
     393    if (cbData + m_cbUsed <= m_cbAllocated)
     394    {
     395        memcpy(&m_pbBuffer[m_cbUsed], pbData, cbData);
     396        m_cbUsed += cbData;
    397397    }
    398398    else
    399399    {
    400400        /* Move any buffered data to the front. */
    401         cbInBuf = m_cbSize - m_cbOffset;
     401        cbInBuf = m_cbUsed - m_offBuffer;
    402402        if (cbInBuf == 0)
    403             m_cbSize = m_cbOffset = 0;
    404         else if (m_cbOffset) /* Do we have something to move? */
    405         {
    406             memmove(m_pbBuffer, &m_pbBuffer[m_cbOffset], cbInBuf);
    407             m_cbSize = cbInBuf;
    408             m_cbOffset = 0;
     403            m_cbUsed = m_offBuffer = 0;
     404        else if (m_offBuffer) /* Do we have something to move? */
     405        {
     406            memmove(m_pbBuffer, &m_pbBuffer[m_offBuffer], cbInBuf);
     407            m_cbUsed = cbInBuf;
     408            m_offBuffer = 0;
    409409        }
    410410
    411411        /* Do we need to grow the buffer? */
    412         if (cbData + m_cbSize > m_cbAllocated)
    413         {
    414             size_t cbAlloc = m_cbSize + cbData;
     412        if (cbData + m_cbUsed > m_cbAllocated)
     413        {
     414/** @todo Put an upper limit on the allocation?   */
     415            size_t cbAlloc = m_cbUsed + cbData;
    415416            cbAlloc = RT_ALIGN_Z(cbAlloc, _64K);
    416417            void *pvNew = RTMemRealloc(m_pbBuffer, cbAlloc);
     
    427428        if (RT_SUCCESS(rc))
    428429        {
    429             if (cbData + m_cbSize <= m_cbAllocated)
     430            if (cbData + m_cbUsed <= m_cbAllocated)
    430431            {
    431                 memcpy(&m_pbBuffer[m_cbSize], pbData, cbData);
    432                 m_cbSize += cbData;
     432                memcpy(&m_pbBuffer[m_cbUsed], pbData, cbData);
     433                m_cbUsed += cbData;
    433434            }
    434435            else
     
    452453
    453454    m_cbAllocated = 0;
    454     m_cbSize = 0;
    455     m_cbOffset = 0;
     455    m_cbUsed = 0;
     456    m_offBuffer = 0;
    456457}
    457458
     
    460461{
    461462    LogFlowFunc(("Dumping contents of stream=0x%p (cbAlloc=%u, cbSize=%u, cbOff=%u) to %s\n",
    462                  m_pbBuffer, m_cbAllocated, m_cbSize, m_cbOffset, pszFile));
     463                 m_pbBuffer, m_cbAllocated, m_cbUsed, m_offBuffer, pszFile));
    463464
    464465    RTFILE hFile;
     
    466467    if (RT_SUCCESS(rc))
    467468    {
    468         rc = RTFileWrite(hFile, m_pbBuffer, m_cbSize, NULL /* pcbWritten */);
     469        rc = RTFileWrite(hFile, m_pbBuffer, m_cbUsed, NULL /* pcbWritten */);
    469470        RTFileClose(hFile);
    470471    }
     
    493494{
    494495    if (   !m_pbBuffer
    495         || !m_cbSize)
     496        || !m_cbUsed)
    496497    {
    497498        return VERR_NO_DATA;
    498499    }
    499500
    500     AssertReturn(m_cbOffset <= m_cbSize, VERR_INVALID_PARAMETER);
    501     if (m_cbOffset == m_cbSize)
     501    AssertReturn(m_offBuffer <= m_cbUsed, VERR_INVALID_PARAMETER);
     502    if (m_offBuffer == m_cbUsed)
    502503        return VERR_NO_DATA;
    503504
    504505    int rc = VINF_SUCCESS;
    505506
    506     char    *pszOff    = (char*)&m_pbBuffer[m_cbOffset];
     507    char    *pszOff    = (char*)&m_pbBuffer[m_offBuffer];
    507508    char    *pszStart  = pszOff;
    508509    uint32_t uDistance;
     
    511512        size_t pairLen = strlen(pszStart);
    512513        uDistance = (pszStart - pszOff);
    513         if (m_cbOffset + uDistance + pairLen + 1 >= m_cbSize)
     514        if (m_offBuffer + uDistance + pairLen + 1 >= m_cbUsed)
    514515        {
    515516            rc = VERR_MORE_DATA;
     
    547548    if (   !uDistance
    548549        && *pszStart == '\0'
    549         && m_cbOffset < m_cbSize)
     550        && m_offBuffer < m_cbUsed)
    550551    {
    551552        uDistance++;
    552553    }
    553     m_cbOffset += uDistance;
     554    m_offBuffer += uDistance;
    554555
    555556    return rc;
  • trunk/src/VBox/Main/src-client/GuestFileImpl.cpp

    r62485 r63154  
    738738    alock.release(); /* Drop write lock before sending. */
    739739
    740     uint32_t cbRead;
    741740    vrc = sendCommand(HOST_FILE_READ, i, paParms);
    742741    if (RT_SUCCESS(vrc))
     742    {
     743        uint32_t cbRead = 0;
    743744        vrc = i_waitForRead(pEvent, uTimeoutMS, pvData, cbData, &cbRead);
    744 
    745     if (RT_SUCCESS(vrc))
    746     {
    747         LogFlowThisFunc(("cbRead=%RU32\n", cbRead));
    748 
    749         if (pcbRead)
    750             *pcbRead = cbRead;
     745        if (RT_SUCCESS(vrc))
     746        {
     747            LogFlowThisFunc(("cbRead=%RU32\n", cbRead));
     748            if (pcbRead)
     749                *pcbRead = cbRead;
     750        }
    751751    }
    752752
     
    794794    alock.release(); /* Drop write lock before sending. */
    795795
    796     uint32_t cbRead;
    797796    vrc = sendCommand(HOST_FILE_READ_AT, i, paParms);
    798797    if (RT_SUCCESS(vrc))
     798    {
     799        uint32_t cbRead = 0;
    799800        vrc = i_waitForRead(pEvent, uTimeoutMS, pvData, cbData, &cbRead);
    800 
    801     if (RT_SUCCESS(vrc))
    802     {
    803         LogFlowThisFunc(("cbRead=%RU32\n", cbRead));
    804 
    805         if (pcbRead)
    806             *pcbRead = cbRead;
     801        if (RT_SUCCESS(vrc))
     802        {
     803            LogFlowThisFunc(("cbRead=%RU32\n", cbRead));
     804
     805            if (pcbRead)
     806                *pcbRead = cbRead;
     807        }
    807808    }
    808809
     
    10991100    alock.release(); /* Drop write lock before sending. */
    11001101
    1101     uint32_t cbWritten;
    11021102    vrc = sendCommand(HOST_FILE_WRITE, i, paParms);
    11031103    if (RT_SUCCESS(vrc))
     1104    {
     1105        uint32_t cbWritten = 0;
    11041106        vrc = i_waitForWrite(pEvent, uTimeoutMS, &cbWritten);
    1105 
    1106     if (RT_SUCCESS(vrc))
    1107     {
    1108         LogFlowThisFunc(("cbWritten=%RU32\n", cbWritten));
    1109 
    1110         if (cbWritten)
    1111             *pcbWritten = cbWritten;
     1107        if (RT_SUCCESS(vrc))
     1108        {
     1109            LogFlowThisFunc(("cbWritten=%RU32\n", cbWritten));
     1110            if (cbWritten)
     1111                *pcbWritten = cbWritten;
     1112        }
    11121113    }
    11131114
     
    11591160    alock.release(); /* Drop write lock before sending. */
    11601161
    1161     uint32_t cbWritten;
    11621162    vrc = sendCommand(HOST_FILE_WRITE_AT, i, paParms);
    11631163    if (RT_SUCCESS(vrc))
     1164    {
     1165        uint32_t cbWritten = 0;
    11641166        vrc = i_waitForWrite(pEvent, uTimeoutMS, &cbWritten);
    1165 
    1166     if (RT_SUCCESS(vrc))
    1167     {
    1168         LogFlowThisFunc(("cbWritten=%RU32\n", cbWritten));
    1169 
    1170         if (cbWritten)
    1171             *pcbWritten = cbWritten;
     1167        if (RT_SUCCESS(vrc))
     1168        {
     1169            LogFlowThisFunc(("cbWritten=%RU32\n", cbWritten));
     1170            if (cbWritten)
     1171                *pcbWritten = cbWritten;
     1172        }
    11721173    }
    11731174
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