Revision | 23125 (tree) |
---|---|
Zeit | 2012-08-03 19:12:43 |
Autor | stefan.fuhrmann.1974 |
When removing log caches back-to-front, we may remove more
than one entry at a time (i.e. if root + UUID match multiple
entries). Instead of using iterators, we must use verifiable
direct indexes.
(Fixes issue #384) : Crash when removing old log caches
@@ -156,13 +156,18 @@ | ||
156 | 156 | // update cache info list and also remove entries |
157 | 157 | // that don't have a cache file anymore |
158 | 158 | |
159 | - for ( const CRepositoryInfo::SPerRepositoryInfo* const * iter | |
160 | - = repositoryInfo->data.end() | |
161 | - , * const *end = repositoryInfo->data.begin() | |
162 | - ; iter != end | |
163 | - ; --iter) | |
159 | + for (size_t i = repositoryInfo->data.size(); i > 0; --i) | |
164 | 160 | { |
165 | - const CRepositoryInfo::SPerRepositoryInfo* info = *(iter-1); | |
161 | + // DropEntry may remove more than one entry per call | |
162 | + | |
163 | + if (i > repositoryInfo->data.size()) | |
164 | + continue; | |
165 | + | |
166 | + // entry still exists. Check whether we have to remove it | |
167 | + | |
168 | + const CRepositoryInfo::SPerRepositoryInfo* info | |
169 | + = repositoryInfo->data[i-1]; | |
170 | + | |
166 | 171 | if ( (deletedCaches.find (info->fileName) != deletedCaches.end()) |
167 | 172 | || (allFiles.find (info->fileName) == allFiles.end())) |
168 | 173 | { |
@@ -289,13 +294,11 @@ | ||
289 | 294 | { |
290 | 295 | std::multimap<CString, CString> result; |
291 | 296 | |
292 | - for ( const CRepositoryInfo::SPerRepositoryInfo* const * iter | |
293 | - = repositoryInfo->data.begin() | |
294 | - , * const *end = repositoryInfo->data.end() | |
295 | - ; iter != end | |
296 | - ; ++iter) | |
297 | + for (size_t i = 0, count = repositoryInfo->data.size(); i != count; ++i) | |
297 | 298 | { |
298 | - const CRepositoryInfo::SPerRepositoryInfo* info = *iter; | |
299 | + const CRepositoryInfo::SPerRepositoryInfo* info | |
300 | + = repositoryInfo->data[i]; | |
301 | + | |
299 | 302 | result.insert (std::make_pair (info->root, info->uuid)); |
300 | 303 | } |
301 | 304 |
@@ -367,16 +367,15 @@ | ||
367 | 367 | |
368 | 368 | // data access |
369 | 369 | |
370 | -const CRepositoryInfo::SPerRepositoryInfo* const * | |
371 | -CRepositoryInfo::CData::begin() const | |
370 | +size_t CRepositoryInfo::CData::size() const | |
372 | 371 | { |
373 | - return data.empty() ? NULL : &data.front(); | |
372 | + return data.size(); | |
374 | 373 | } |
375 | 374 | |
376 | -const CRepositoryInfo::SPerRepositoryInfo* const * | |
377 | -CRepositoryInfo::CData::end() const | |
375 | +const CRepositoryInfo::SPerRepositoryInfo* | |
376 | +CRepositoryInfo::CData::operator[](size_t index) const | |
378 | 377 | { |
379 | - return begin() + data.size(); | |
378 | + return data[index]; | |
380 | 379 | } |
381 | 380 | |
382 | 381 | // share the repository info pool thoughout this application |
@@ -170,8 +170,8 @@ | ||
170 | 170 | |
171 | 171 | /// data access |
172 | 172 | |
173 | - const SPerRepositoryInfo* const * begin() const; | |
174 | - const SPerRepositoryInfo* const * end() const; | |
173 | + size_t size() const; | |
174 | + const SPerRepositoryInfo* operator[](size_t index) const; | |
175 | 175 | }; |
176 | 176 | |
177 | 177 | /// cached repository properties |