From 44ee3f48d3a1a4aacc9360b9e19cc7451807d009 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Thu, 14 Nov 2024 22:20:09 +0200 Subject: [PATCH] chore: fix plain node insertion The blob allocation had invalid size and the value has never been copied. Signed-off-by: Roman Gershman --- src/core/qlist.cc | 2 +- src/core/qlist_test.cc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/qlist.cc b/src/core/qlist.cc index 4b4825e31092..01fa2e93513a 100644 --- a/src/core/qlist.cc +++ b/src/core/qlist.cc @@ -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); diff --git a/src/core/qlist_test.cc b/src/core/qlist_test.cc index da469b0fea40..0b347010311c 100644 --- a/src/core/qlist_test.cc +++ b/src/core/qlist_test.cc @@ -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; class PrintToFillCompress {