Skip to content

Commit efd02b4

Browse files
authored
Fix: add a guard clause and change the type of _size in 3LCache (#251)
Enhancement: Change the type of _size from int32_t to uint64_t to support larger objects and cache sizes, preventing std::bad_array_new_length.
1 parent 0b97ac4 commit efd02b4

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

libCacheSim/cache/eviction/3LCache/ThreeLCache.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,15 @@ void ThreeLCacheCache::evict() {
307307
}
308308

309309
void ThreeLCacheCache::evict_with_candidate(pair<uint64_t, int32_t> &epair) {
310+
int32_t old_pos = epair.second;
311+
if (old_pos == -1) {
312+
// No valid candidate to evict, avoid segfault
313+
return;
314+
}
315+
310316
is_sampling = true;
311317
evict_nums -= 1;
312318
uint64_t key = epair.first;
313-
int32_t old_pos = epair.second;
314319
_currentSize -= in_cache.metas[old_pos]._size;
315320

316321
pred_map.erase(key);

libCacheSim/cache/eviction/3LCache/ThreeLCache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct MetaExtra {
6666
class Meta {
6767
public:
6868
uint64_t _key;
69-
int32_t _size;
69+
uint64_t _size;
7070
uint64_t _past_timestamp;
7171
uint16_t _freq;
7272
MetaExtra *_extra = nullptr;

0 commit comments

Comments
 (0)