From dc812b80bd8555af7952bc9110a26047f407aa52 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Fri, 5 Jul 2024 20:02:13 +0800 Subject: [PATCH] rewindPath shouldn't modify arg --- tracker/tracker.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tracker/tracker.go b/tracker/tracker.go index 8c14ddc..1176c29 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -253,20 +253,21 @@ func (it *Iterator) Bounds() ([]byte, []byte) { return nil, nil } -// Rewinds to the path of the previous (pre-order) node: +// Returns the path, rewound to the previous (pre-order) node: +// If path is the root (empty) or a leaf path, it's returned. // If the last byte of the path is zero, pops it (e.g. [1 0] => [1]). // Otherwise, decrements it and pads with 0xF to 64 bytes (e.g. [1] => [0 f f f ...]). // The passed slice is not modified. func rewindPath(path []byte) []byte { - if len(path) == 0 { + if len(path) == 0 || path[len(path)-1] == 0x10 { return path } if path[len(path)-1] == 0 { return path[:len(path)-1] } - path[len(path)-1]-- padded := make([]byte, 64) i := copy(padded, path) + padded[len(path)-1]-- for ; i < len(padded); i++ { padded[i] = 0xf }