VirtualBox

Changeset 16164 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jan 22, 2009 1:21:40 PM (16 years ago)
Author:
vboxsync
Message:

rtZipStoreCompress: g++ (GCC) 4.1.2 (Gentoo 4.1.2 p1.1) generates incorrect code if '(uintptr_t)&pZip->abBuffer[sizeof(pZip->abBuffer)] - (uintptr_t)pZip->u.Store.pb' is used to calc remaining buffer space, 'sizeof(pZip->abBuffer) - (size_t)(pbDst - &pZip->abBuffer[0])' seems to work though. (It was looping endlessly, with cb=0, seems it had figured that the branch wasn't gonna be taken then.)

File:
1 edited

Legend:

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

    r14055 r16164  
    248248
    249249#ifdef RTZIP_USE_STORE
     250#include <stdio.h>
    250251
    251252/**
     
    254255static DECLCALLBACK(int) rtZipStoreCompress(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf)
    255256{
     257    uint8_t *pbDst = pZip->u.Store.pb;
    256258    while (cbBuf)
    257259    {
     
    259261         * Flush.
    260262         */
    261         size_t cb = (uintptr_t)&pZip->abBuffer[sizeof(pZip->abBuffer)] - (uintptr_t)pZip->u.Store.pb;
    262         if (cb <= 0)
     263        size_t cb = sizeof(pZip->abBuffer) - (size_t)(pbDst - &pZip->abBuffer[0]); /* careful here, g++ 4.1.2 screws up easily */
     264        if (cb == 0)
    263265        {
    264266            int rc = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer));
    265267            if (RT_FAILURE(rc))
    266268                return rc;
     269
    267270            cb = sizeof(pZip->abBuffer);
    268             pZip->u.Store.pb = &pZip->abBuffer[0];
     271            pbDst = &pZip->abBuffer[0];
    269272        }
    270273
     
    274277        if (cbBuf < cb)
    275278            cb = cbBuf;
    276         memcpy(pZip->u.Store.pb, pvBuf, cb);
    277         pZip->u.Store.pb += cb;
     279        memcpy(pbDst, pvBuf, cb);
     280
     281        pbDst += cb;
    278282        cbBuf -= cb;
    279283        pvBuf = (uint8_t *)pvBuf + cb;
    280284    }
     285    pZip->u.Store.pb = pbDst;
    281286    return VINF_SUCCESS;
    282287}
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