Skip to content

Commit

Permalink
fix: rootKey empty check by len equals 0 (#801)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <marbar3778@yahoo.com>
(cherry picked from commit 06f5be1)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
mmsqe authored and mergify[bot] committed Aug 10, 2023
1 parent bcdaadf commit 9c9eee2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
### Bug Fixes

- [#773](https://github.com/cosmos/iavl/pull/773) Fix memory leak in `Import`.
<<<<<<< HEAD
=======
- [#795](https://github.com/cosmos/iavl/pull/795) Fix plugin used for buf generate.
- [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0.
>>>>>>> 06f5be1 (fix: rootKey empty check by len equals 0 (#801))
### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ type NodeIterator struct {

// NewNodeIterator returns a new NodeIterator to traverse the tree of the root node.
func NewNodeIterator(rootKey []byte, ndb *nodeDB) (*NodeIterator, error) {
if rootKey == nil {
if len(rootKey) == 0 {
return &NodeIterator{
nodesToVisit: []*Node{},
ndb: ndb,
Expand Down
4 changes: 4 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,8 @@ func TestNodeIterator_WithEmptyRoot(t *testing.T) {
itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil, log.NewNopLogger()))
require.NoError(t, err)
require.False(t, itr.Valid())

itr, err = NewNodeIterator([]byte{}, newNodeDB(dbm.NewMemDB(), 0, nil, log.NewNopLogger()))
require.NoError(t, err)
require.False(t, itr.Valid())
}

0 comments on commit 9c9eee2

Please # to comment.