VirtualBox

Changeset 65545 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 31, 2017 3:27:09 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
113192
Message:

log.cpp: Keep offScratch in a local variable so we have consistent results regardless what's going on.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r63509 r65545  
    35113511        for (;;)
    35123512        {
    3513             size_t      cb = sizeof(pLogger->achScratch) - pLogger->offScratch - 1;
     3513            uint32_t    offScratch = pLogger->offScratch;
     3514            size_t      cb         = sizeof(pLogger->achScratch) - offScratch - 1;
    35143515            const char *pszNewLine;
    35153516            char       *psz;
     
    35293530#if defined(DEBUG) && defined(IN_RING3)
    35303531                /* sanity */
    3531                 if (pLogger->offScratch >= sizeof(pLogger->achScratch))
     3532                if (offScratch >= sizeof(pLogger->achScratch))
    35323533                {
    3533                     fprintf(stderr, "pLogger->offScratch >= sizeof(pLogger->achScratch) (%#x >= %#x)\n",
    3534                             pLogger->offScratch, (unsigned)sizeof(pLogger->achScratch));
     3534                    fprintf(stderr, "offScratch >= sizeof(pLogger->achScratch) (%#x >= %#x)\n",
     3535                            offScratch, (unsigned)sizeof(pLogger->achScratch));
    35353536                    AssertBreakpoint(); AssertBreakpoint();
    35363537                }
     
    35443545                {
    35453546                    rtlogFlush(pLogger);
    3546                     cb = sizeof(pLogger->achScratch) - pLogger->offScratch - 1;
     3547                    offScratch = pLogger->offScratch;
     3548                    cb = sizeof(pLogger->achScratch) - offScratch - 1;
    35473549                }
    35483550
     
    35513553                 * psz is pointing to the current position.
    35523554                 */
    3553                 psz = &pLogger->achScratch[pLogger->offScratch];
     3555                psz = &pLogger->achScratch[offScratch];
    35543556                if (pLogger->fFlags & RTLOGFLAGS_PREFIX_TS)
    35553557                {
     
    38333835                 * Done, figure what we've used and advance the buffer and free size.
    38343836                 */
    3835                 cb = psz - &pLogger->achScratch[pLogger->offScratch];
     3837                cb = psz - &pLogger->achScratch[offScratch];
    38363838                AssertMsg(cb <= 223, ("%#zx (%zd) - fFlags=%#x\n", cb, cb, pLogger->fFlags));
    3837                 pLogger->offScratch += (uint32_t)cb;
    3838                 cb = sizeof(pLogger->achScratch) - pLogger->offScratch - 1;
     3839                pLogger->offScratch = offScratch += (uint32_t)cb;
     3840                cb = sizeof(pLogger->achScratch) - offScratch - 1;
    38393841            }
    38403842            else if (cb <= 0)
    38413843            {
    38423844                rtlogFlush(pLogger);
    3843                 cb = sizeof(pLogger->achScratch) - pLogger->offScratch - 1;
     3845                offScratch = pLogger->offScratch;
     3846                cb = sizeof(pLogger->achScratch) - offScratch - 1;
    38443847            }
    38453848
    38463849#if defined(DEBUG) && defined(IN_RING3)
    38473850            /* sanity */
    3848             if (pLogger->offScratch >= sizeof(pLogger->achScratch))
     3851            if (offScratch >= sizeof(pLogger->achScratch))
    38493852            {
    3850                 fprintf(stderr, "pLogger->offScratch >= sizeof(pLogger->achScratch) (%#x >= %#x)\n",
    3851                         pLogger->offScratch, (unsigned)sizeof(pLogger->achScratch));
     3853                fprintf(stderr, "offScratch >= sizeof(pLogger->achScratch) (%#x >= %#x)\n",
     3854                        offScratch, (unsigned)sizeof(pLogger->achScratch));
    38523855                AssertBreakpoint(); AssertBreakpoint();
    38533856            }
     
    38723875
    38733876            /* copy */
    3874             memcpy(&pLogger->achScratch[pLogger->offScratch], pachChars, cb);
     3877            memcpy(&pLogger->achScratch[offScratch], pachChars, cb);
    38753878
    38763879            /* advance */
    3877             pLogger->offScratch += (uint32_t)cb;
     3880            pLogger->offScratch = offScratch += (uint32_t)cb;
    38783881            cbRet += cb;
    38793882            cbChars -= cb;
     
    38813884            if (    pszNewLine
    38823885                &&  (pLogger->fFlags & RTLOGFLAGS_USECRLF)
    3883                 &&  pLogger->offScratch + 2 < sizeof(pLogger->achScratch))
     3886                &&  offScratch + 2 < sizeof(pLogger->achScratch))
    38843887            {
    3885                 memcpy(&pLogger->achScratch[pLogger->offScratch], "\r\n", 2);
    3886                 pLogger->offScratch += 2;
     3888                memcpy(&pLogger->achScratch[offScratch], "\r\n", 2);
     3889                pLogger->offScratch = offScratch += 2;
    38873890                cbRet++;
    38883891                cbChars--;
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