chore: fix plain node insertion (#4134)

The blob allocation had invalid size and the value has never been copied.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-11-14 23:53:34 +02:00 committed by GitHub
parent db67b35f8e
commit c46cb2514f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -156,9 +156,9 @@ quicklistNode* CreateNode(int container, string_view value) {
if (container == QUICKLIST_NODE_CONTAINER_PLAIN) { if (container == QUICKLIST_NODE_CONTAINER_PLAIN) {
DCHECK(!value.empty()); DCHECK(!value.empty());
new_node->sz = value.size();
new_node->entry = (uint8_t*)zmalloc(new_node->sz); new_node->entry = (uint8_t*)zmalloc(new_node->sz);
memcpy(new_node->entry, value.data(), new_node->sz); memcpy(new_node->entry, value.data(), new_node->sz);
new_node->sz = value.size();
} else { } else {
new_node->entry = LP_Prepend(lpNew(0), value); new_node->entry = LP_Prepend(lpNew(0), value);
new_node->sz = lpBytes(new_node->entry); new_node->sz = lpBytes(new_node->entry);

View file

@ -236,6 +236,14 @@ TEST_F(QListTest, InsertDelete) {
EXPECT_EQ(0, ql_.Size()); 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>; using FillCompress = tuple<int, unsigned>;
class PrintToFillCompress { class PrintToFillCompress {