Skip to content

Commit

Permalink
chore: fix plain node insertion (#4134)
Browse files Browse the repository at this point in the history
The blob allocation had invalid size and the value has never been copied.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Nov 14, 2024
1 parent db67b35 commit c46cb25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ quicklistNode* CreateNode(int container, string_view value) {

if (container == QUICKLIST_NODE_CONTAINER_PLAIN) {
DCHECK(!value.empty());
new_node->sz = value.size();
new_node->entry = (uint8_t*)zmalloc(new_node->sz);
memcpy(new_node->entry, value.data(), new_node->sz);
new_node->sz = value.size();
} else {
new_node->entry = LP_Prepend(lpNew(0), value);
new_node->sz = lpBytes(new_node->entry);
Expand Down
8 changes: 8 additions & 0 deletions src/core/qlist_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ TEST_F(QListTest, InsertDelete) {
EXPECT_EQ(0, ql_.Size());
}

TEST_F(QListTest, PushPlain) {
// push a value large enough to trigger plain node insertion.
string val(9000, 'a');
ql_.Push(val, QList::HEAD);
auto items = ToItems();
EXPECT_THAT(items, ElementsAre(val));
}

using FillCompress = tuple<int, unsigned>;

class PrintToFillCompress {
Expand Down

0 comments on commit c46cb25

Please sign in to comment.