Skip to content

Commit

Permalink
Detect pages that have multiple flags set.
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Tabor <ptab@google.com>
  • Loading branch information
ptabor committed Dec 23, 2022
1 parent d1aa803 commit 3cbd9c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ func (n *node) read(p *page) {
func (n *node) write(p *page) {
// Initialize page.
if n.isLeaf {
p.flags |= leafPageFlag
p.flags = leafPageFlag
} else {
p.flags |= branchPageFlag
p.flags = branchPageFlag
}

if len(n.inodes) >= 0xFFFF {
Expand Down
11 changes: 7 additions & 4 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bbolt

import (
"fmt"
"log"
"os"
"sort"
"unsafe"
Expand Down Expand Up @@ -55,9 +54,13 @@ func (p *page) meta() *meta {
}

func (p *page) fastCheck(id pgid) {
if p.id != id {
log.Panicf("Page expected to be: %v, but self identifies as %v", id, p.id)
}
_assert(p.id == id, "Page expected to be: %v, but self identifies as %v", id, p.id)
// Only one flag of page-type can be set.
_assert(p.flags == branchPageFlag ||
p.flags == leafPageFlag ||
p.flags == metaPageFlag ||
p.flags == freelistPageFlag,
"page %v: has unexpected type/flags: %x", p.id, p.flags)
}

// leafPageElement retrieves the leaf node by index
Expand Down

0 comments on commit 3cbd9c9

Please sign in to comment.