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 {