cockroachdb-parser
cockroachdb-parser copied to clipboard
Fix integer overflow on 32-bit architectures
Problem
On 32-bit architectures (such as OpenBSD ARM, Linux ARM, etc.), building the parser fails with integer overflow errors:
pkg/util/tsearch/eval.go:180:11: cannot use math.MaxInt64 (untyped int constant 9223372036854775807) as int value in assignment (overflows)
pkg/sql/sem/tree/format.go:185:2: FmtFlags(lexbase.EncFirstFreeFlagBit) << iota (constant 2147483648 of int type FmtFlags) overflows int
The issue occurs because:
inttype is 32-bit on 32-bit architectures- Variables declared as
intcannot hold 64-bit values likemath.MaxInt64 - Bit shift operations that produce values > 32 bits overflow
Solution
This PR changes the affected types from int to int64:
- pkg/util/tsearch/eval.go: Changed
lPosandrPosvariables frominttoint64to accommodatemath.MaxInt64 - pkg/sql/lexbase/encode.go: Changed
EncodeFlagstype frominttoint64to support large bit shift operations - pkg/sql/sem/tree/format.go: Changed
FmtFlagstype frominttoint64for the same reason
Testing
Successfully built and tested on:
GOOS=openbsd GOARCH=arm(32-bit)- Standard 64-bit platforms (Linux amd64, Darwin arm64)
The changes are backward compatible since int64 is a superset of int on all platforms.
Impact
- Minimal performance impact (int64 operations are native on all modern CPUs)
- Enables builds on 32-bit architectures
- No API changes or breaking changes