diff --git a/leveldb/db.go b/leveldb/db.go index 0cc16e2..d9c2939 100644 --- a/leveldb/db.go +++ b/leveldb/db.go @@ -345,7 +345,7 @@ func (db *DB) get(r []byte, ro *ReadOptions, key []byte) ([]byte, error) { defer C.leveldb_get_free_ext(unsafe.Pointer(c)) - if int(C.int(vallen)) > len(r) { + if r == nil || int(C.int(vallen)) > len(r) { return C.GoBytes(unsafe.Pointer(value), C.int(vallen)), nil } else { b := slice(unsafe.Pointer(value), int(C.int(vallen))) diff --git a/leveldb/iterator.go b/leveldb/iterator.go index 3e4192a..c972fe0 100644 --- a/leveldb/iterator.go +++ b/leveldb/iterator.go @@ -98,7 +98,7 @@ func (it *Iterator) BufKey(b []byte) []byte { if k == nil { return nil } - if len(k) > len(b) { + if b == nil || len(k) > len(b) { b = make([]byte, len(k)) } @@ -112,7 +112,7 @@ func (it *Iterator) BufValue(b []byte) []byte { if v == nil { return nil } - if len(v) > len(b) { + if b == nil || len(v) > len(b) { b = make([]byte, len(v)) } @@ -208,6 +208,14 @@ func (it *RangeLimitIterator) RawValue() []byte { return it.it.RawValue() } +func (it *RangeLimitIterator) BufKey(b []byte) []byte { + return it.it.BufKey(b) +} + +func (it *RangeLimitIterator) BufValue(b []byte) []byte { + return it.it.BufValue(b) +} + func (it *RangeLimitIterator) Valid() bool { if it.l.Offset < 0 { return false