From 6669135c4479cbe330b504629b868712ab241d5a Mon Sep 17 00:00:00 2001 From: Alasdair Date: Wed, 30 Oct 2019 23:46:26 -0400 Subject: [PATCH] add nil check to Dtrie.Get() ensures Dtrie.Get() doesn't panic on key not found --- trie/dtrie/dtrie.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trie/dtrie/dtrie.go b/trie/dtrie/dtrie.go index c3abca2..4608de3 100644 --- a/trie/dtrie/dtrie.go +++ b/trie/dtrie/dtrie.go @@ -80,7 +80,11 @@ func (d *Dtrie) Size() (size int) { // Get returns the value for the associated key or returns nil if the // key does not exist. func (d *Dtrie) Get(key interface{}) interface{} { - return get(d.root, d.hasher(key), key).Value() + node := get(d.root, d.hasher(key), key) + if node != nil { + return node.Value() + } + return nil } // Insert adds a key value pair to the Dtrie, replacing the existing value if