From bab8a7090aa509affdb4490dca0fee97384c2173 Mon Sep 17 00:00:00 2001 From: Jussi Maki Date: Mon, 29 Apr 2024 15:27:18 +0200 Subject: [PATCH] part: Fix returned old value for non-leaf nodes Signed-off-by: Jussi Maki --- part/txn.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/part/txn.go b/part/txn.go index b3d9b23..ae35c91 100644 --- a/part/txn.go +++ b/part/txn.go @@ -173,12 +173,14 @@ func (txn *Txn[T]) insert(root *header[T], key []byte, value T) (oldValue T, had if bytes.HasPrefix(key, this.prefix) { key = key[len(this.prefix):] if len(key) == 0 { + leaf := this.getLeaf() + if leaf != nil { + oldValue = leaf.value + hadOld = true + } if this.isLeaf() { // This is a leaf node and we just cloned it. Update the value. - leaf := this.getLeaf() - oldValue = leaf.value leaf.value = value - hadOld = true } else { // This is a non-leaf node, create/replace the existing leaf. this.setLeaf(newLeaf(txn.opts, key, fullKey, value))