Skip to content

Commit df92e60

Browse files
committed
bson/bsoncodec: check kind encoder cache size at startup
This check will guard against changes to the reflect.Kind constants.
1 parent c65de30 commit df92e60

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

bson/bsoncodec/codec_cache.go

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ func (c *typeDecoderCache) Clone() *typeDecoderCache {
8282
return cc
8383
}
8484

85+
func init() {
86+
if s := reflect.Kind(len(kindEncoderCache{}.entries)).String(); s != "kind27" {
87+
panic("The capacity of kindEncoderCache is too small.\n" +
88+
"This is due to a new type being added to reflect.Kind.")
89+
}
90+
}
91+
8592
// atomic.Value requires that all calls to Store() have the same concrete type
8693
// so we wrap the ValueEncoder with a kindEncoderCacheEntry to ensure the type
8794
// is always the same (since different concrete types may implement the

0 commit comments

Comments
 (0)