mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
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:
parent
db67b35f8e
commit
c46cb2514f
2 changed files with 9 additions and 1 deletions
|
@ -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);
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue