Changeset 5841 for trunk/src/kernel32/ccollection.cpp
- Timestamp:
- May 30, 2001, 8:33:00 PM (24 years ago)
- File:
-
- 1 edited
-
trunk/src/kernel32/ccollection.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/ccollection.cpp
r5838 r5841 1 /* $Id: ccollection.cpp,v 1. 4 2001-05-30 13:02:55phaller Exp $ */1 /* $Id: ccollection.cpp,v 1.5 2001-05-30 18:29:59 phaller Exp $ */ 2 2 3 3 /* … … 87 87 // shrink the index array to the absolutely necessary size only 88 88 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 89 101 // verify if shrink can do anything good 90 102 if ( (iOffset < iUsedOffset) || … … 106 118 int iRelative = iUsedOffset - iOffset; 107 119 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)); 111 127 112 128 // deferred delete ensures we've always got a valid array … … 153 169 { 154 170 // copy the data, array cannot overlap 155 memmove(pNewData ,171 memmove(pNewData + (iShift * sizeof(INDEXLOOKUPENTRY)), 156 172 pEntries, 157 iSize );173 iSize * sizeof(INDEXLOOKUPENTRY)); 158 174 159 175 // zero out at the beginning or at the end … … 214 230 PINDEXLOOKUPENTRY pTemp = pEntries; 215 231 pEntries = pNewData; 216 free(pTemp); 232 if (pTemp) 233 free(pTemp); 217 234 218 235 iSize = iRequiredSize; … … 236 253 PINDEXLOOKUPENTRY pTemp = pEntries; 237 254 pEntries = pNewData; 238 free(pTemp); 239 255 if (pTemp) 256 free(pTemp); 257 240 258 iSize = iRequiredSize; 241 259 iHigh = iIndex; … … 261 279 if (iIndex > iUsedHigh) 262 280 iUsedHigh = iIndex; 281 282 // used limits are not initialized 283 iInitialized = 1; 263 284 264 285 // insert entry and quit … … 302 323 iUsedOffset = INT_MAX; 303 324 iUsedHigh = INT_MIN; 325 iInitialized = 0; 304 326 } 305 327 … … 318 340 } 319 341 } 320 321 342 322 343
Note:
See TracChangeset
for help on using the changeset viewer.
