Skip to content

Commit

Permalink
fix: Do not attempt to defrag StringSet as a StringMap (#4283)
Browse files Browse the repository at this point in the history
That'd be a total waste of time and energy, not to mention you'll crash.

Fixes #4167
  • Loading branch information
chakaz authored and romange committed Dec 10, 2024
1 parent c49dc61 commit cd3ef9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/compact_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ pair<void*, bool> DefragSet(unsigned encoding, void* ptr, float ratio) {
return DefragIntSet((intset*)ptr, ratio);
}

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

default:
Expand Down
9 changes: 9 additions & 0 deletions src/core/compact_object_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "core/detail/bitpacking.h"
#include "core/flat_set.h"
#include "core/mi_memory_resource.h"
#include "core/string_set.h"

extern "C" {
#include "redis/intset.h"
Expand Down Expand Up @@ -575,6 +576,14 @@ TEST_F(CompactObjectTest, DefragHash) {
}
}

TEST_F(CompactObjectTest, DefragSet) {
// This is still not implemented
StringSet* s = new StringSet();
s->Add("str");
cobj_.InitRobj(OBJ_SET, kEncodingStrMap2, s);
ASSERT_FALSE(cobj_.DefragIfNeeded(0.8));
}

TEST_F(CompactObjectTest, RawInterface) {
string str(50, 'a'), tmp, owned;
cobj_.SetString(str);
Expand Down

0 comments on commit cd3ef9a

Please sign in to comment.