Skip to content

Commit

Permalink
add nil check to Dtrie.Get()
Browse files Browse the repository at this point in the history
ensures Dtrie.Get() doesn't panic on key not found
  • Loading branch information
AliceBennett committed Oct 31, 2019
1 parent f07cbe3 commit 6669135
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion trie/dtrie/dtrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6669135

Please sign in to comment.