Ignore:
Timestamp:
May 30, 2001, 8:33:00 PM (24 years ago)
Author:
phaller
Message:

.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/ccollection.cpp

    r5838 r5841  
    1 /* $Id: ccollection.cpp,v 1.4 2001-05-30 13:02:55 phaller Exp $ */
     1/* $Id: ccollection.cpp,v 1.5 2001-05-30 18:29:59 phaller Exp $ */
    22
    33/*
     
    8787    // shrink the index array to the absolutely necessary size only
    8888
     89    if (iInitialized == 0)
     90    {
     91        // if no elements were allocated, simple remove all data memory
     92        if (pEntries)
     93        {
     94            free(pEntries);
     95            pEntries = NULL;
     96        }
     97
     98        return 1;
     99    }
     100
    89101    // verify if shrink can do anything good
    90102    if ( (iOffset < iUsedOffset) ||
     
    106118            int iRelative = iUsedOffset - iOffset;
    107119
    108             memcpy(pNewData,
    109                    pEntries + (iRelative * sizeof(INDEXLOOKUPENTRY)),
    110                    iRequiredSize * sizeof(INDEXLOOKUPENTRY));
     120            // Note: due to C++ pointer arithmetic,
     121            // (pEntries + iRelative) should automatically
     122            // increase pEntries by iRelative-times the
     123            // sizeof(INDEXLOOKUPENTRY) byte positions!
     124            memmove(pNewData,
     125                    pEntries + iRelative,
     126                    iRequiredSize * sizeof(INDEXLOOKUPENTRY));
    111127   
    112128            // deferred delete ensures we've always got a valid array
     
    153169    {
    154170        // copy the data, array cannot overlap
    155         memmove(pNewData,
     171        memmove(pNewData + (iShift * sizeof(INDEXLOOKUPENTRY)),
    156172                pEntries,
    157                 iSize);
     173                iSize * sizeof(INDEXLOOKUPENTRY));
    158174
    159175        // zero out at the beginning or at the end
     
    214230            PINDEXLOOKUPENTRY pTemp = pEntries;
    215231            pEntries = pNewData;
    216             free(pTemp);
     232            if (pTemp)
     233                free(pTemp);
    217234
    218235            iSize = iRequiredSize;
     
    236253                PINDEXLOOKUPENTRY pTemp = pEntries;
    237254                pEntries = pNewData;
    238                 free(pTemp);
    239 
     255                if (pTemp)
     256                    free(pTemp);
     257               
    240258                iSize = iRequiredSize;
    241259                iHigh = iIndex;
     
    261279        if (iIndex > iUsedHigh)
    262280            iUsedHigh = iIndex;
     281
     282        // used limits are not initialized
     283        iInitialized = 1;
    263284
    264285        // insert entry and quit
     
    302323    iUsedOffset = INT_MAX;
    303324    iUsedHigh = INT_MIN;
     325    iInitialized = 0;
    304326}
    305327
     
    318340    }
    319341}
    320 
    321342
    322343
Note: See TracChangeset for help on using the changeset viewer.