Skip to content

Commit

Permalink
fix empty collection cursor seek panic (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Preetam committed May 24, 2017
1 parent ed672fe commit 110bbf2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *Cursor) Seek(key string) {
rec, err = c.collection.readRecord(c.collection.Head)
c.collection.metaLock.RUnlock()
if err != nil {
if atomic.LoadInt64(&c.current.Next) != 0 {
if c.current != nil && atomic.LoadInt64(&c.current.Next) != 0 {
c.err = err
}
c.current = nil
Expand Down
19 changes: 19 additions & 0 deletions lm2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,22 @@ func TestSeekOverwrittenKey(t *testing.T) {
t.Fatal(err)
}
}

func TestEmptyCollectionCursorSeekPanic(t *testing.T) {
c, err := NewCollection("/tmp/test_emptycollectioncursorseekpanic.lm2", 100)
if err != nil {
t.Fatal(err)
}
defer c.Destroy()

cur, err := c.NewCursor()
if err != nil {
t.Fatal(err)
}

cur.Seek("asdf")

if cur.Valid() {
t.Errorf("expected cur.Valid() to return false")
}
}

0 comments on commit 110bbf2

Please sign in to comment.