Skip to content

Commit cd3ef9a

Browse files
chakazromange
authored andcommitted
fix: Do not attempt to defrag StringSet as a StringMap (#4283)
That'd be a total waste of time and energy, not to mention you'll crash. Fixes #4167
1 parent c49dc61 commit cd3ef9a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/core/compact_object.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ pair<void*, bool> DefragSet(unsigned encoding, void* ptr, float ratio) {
215215
return DefragIntSet((intset*)ptr, ratio);
216216
}
217217

218-
// StringMap supports re-allocation of it's internal nodes
219218
case kEncodingStrMap2: {
220-
return DefragStrMap2((StringMap*)ptr, ratio);
219+
// Still not implemented
220+
return {ptr, false};
221221
}
222222

223223
default:

src/core/compact_object_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "core/detail/bitpacking.h"
1717
#include "core/flat_set.h"
1818
#include "core/mi_memory_resource.h"
19+
#include "core/string_set.h"
1920

2021
extern "C" {
2122
#include "redis/intset.h"
@@ -575,6 +576,14 @@ TEST_F(CompactObjectTest, DefragHash) {
575576
}
576577
}
577578

579+
TEST_F(CompactObjectTest, DefragSet) {
580+
// This is still not implemented
581+
StringSet* s = new StringSet();
582+
s->Add("str");
583+
cobj_.InitRobj(OBJ_SET, kEncodingStrMap2, s);
584+
ASSERT_FALSE(cobj_.DefragIfNeeded(0.8));
585+
}
586+
578587
TEST_F(CompactObjectTest, RawInterface) {
579588
string str(50, 'a'), tmp, owned;
580589
cobj_.SetString(str);

0 commit comments

Comments
 (0)