bugfix: BufGet must make if b is nil

This commit is contained in:
siddontang 2014-07-07 14:50:58 +08:00
parent 66d2b3b8ba
commit 51a5dc9212
2 changed files with 11 additions and 3 deletions

View File

@ -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)))

View File

@ -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