Skip to content

Commit 6866381

Browse files
committed
fixes: panic on empty trie iteration #6
1 parent 0e5c155 commit 6866381

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

trie/tst.go

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ func (self *TST) Iterate() KVIterator {
212212
kv_iterator = func() (key Hashable, value interface{}, next KVIterator) {
213213
var tn TreeNode
214214
for {
215+
if tni == nil {
216+
return nil, nil, nil
217+
}
215218
tn, tni = tni()
216219
if tni == nil {
217220
return nil, nil, nil

trie/tst_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ func (self ByteSlices) Swap(i, j int) {
7070
self[i], self[j] = self[j], self[i]
7171
}
7272

73+
func TestEmptyIter(t *testing.T) {
74+
table := New()
75+
for _, _, next := table.Iterate()(); next != nil; _, _, next = next() {
76+
t.Errorf("should have been empty")
77+
}
78+
79+
}
80+
7381
func TestIteratorPrefixFindDotty(t *testing.T) {
7482
items := ByteSlices{
7583
types.ByteSlice("0:java.io.File;"),

0 commit comments

Comments
 (0)