From 7adfa44e02041a6d9b571025a8237a13fa6fbde8 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 22 Dec 2016 17:22:44 -0800 Subject: [PATCH] Fix freelist.size calculation for large freelists freelist.size did not account for the extra fake freelist item used to hold the number of elements when the freelist is large. --- freelist.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/freelist.go b/freelist.go index de59aaa..aba48f5 100644 --- a/freelist.go +++ b/freelist.go @@ -24,7 +24,12 @@ func newFreelist() *freelist { // size returns the size of the page after serialization. func (f *freelist) size() int { - return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * f.count()) + n := f.count() + if n >= 0xFFFF { + // The first element will be used to store the count. See freelist.write. + n++ + } + return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * n) } // count returns count of pages on the freelist