From 81f25783ae43c0699147f7d8b251753ede487a5b Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Sun, 3 May 2020 17:32:57 +0000 Subject: [PATCH] Shorten max array lengths for the data type --- page.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/page.go b/page.go index 3cfd94e9d..334f0ab8c 100644 --- a/page.go +++ b/page.go @@ -64,7 +64,8 @@ func (p *page) leafPageElements() []leafPageElement { if p.count == 0 { return nil } - return (*[maxAllocSize]leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), + const maxArraySize = maxAllocSize / unsafe.Sizeof(leafPageElement{}) + return (*[maxArraySize]leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), unsafe.Sizeof(leafPageElement{}), 0))[:p.count:p.count] } @@ -79,7 +80,8 @@ func (p *page) branchPageElements() []branchPageElement { if p.count == 0 { return nil } - return (*[maxAllocSize]branchPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), + const maxArraySize = maxAllocSize / unsafe.Sizeof(branchPageElement{}) + return (*[maxArraySize]branchPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p), unsafe.Sizeof(branchPageElement{}), 0))[:p.count:p.count] }