trie/bintrie: panic on makeRef index overflow

Silently masking the index with indexMask would let an oversized idx
collide with emptyRef (makeRef(kindEmpty, 0)): e.g. makeRef(kindEmpty,
1<<30) returned emptyRef, which IsEmpty would accept as absent even
though the caller meant to reference a real node. Panic instead.
allocInternal/allocStem/allocHashed already panic on pool overflow,
so this is a belt-and-suspenders guard for any direct callers.
This commit is contained in:
CPerezz 2026-04-19 22:15:38 +02:00
parent 6e36636c9c
commit c08048eb84
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -42,7 +42,10 @@ const (
)
func makeRef(kind nodeKind, idx uint32) nodeRef {
return nodeRef(uint32(kind)<<kindShift | (idx & indexMask))
if idx > indexMask {
panic("nodeRef index overflow")
}
return nodeRef(uint32(kind)<<kindShift | idx)
}
func (r nodeRef) Kind() nodeKind { return nodeKind(uint32(r) >> kindShift) }