Skip to content

Conversation

@chrislusf
Copy link

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:

  1. int type is 32-bit on 32-bit architectures
  2. Variables declared as int cannot hold 64-bit values like math.MaxInt64
  3. Bit shift operations that produce values > 32 bits overflow

Solution

This PR changes the affected types from int to int64:

  1. pkg/util/tsearch/eval.go: Changed lPos and rPos variables from int to int64 to accommodate math.MaxInt64
  2. pkg/sql/lexbase/encode.go: Changed EncodeFlags type from int to int64 to support large bit shift operations
  3. pkg/sql/sem/tree/format.go: Changed FmtFlags type from int to int64 for 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

On 32-bit architectures (like OpenBSD ARM), int is 32-bit and cannot
hold math.MaxInt64. Changed lPos and rPos to int64 to fix overflow
errors when building for GOOS=openbsd GOARCH=arm.
On 32-bit architectures, EncodeFlags and FmtFlags need to be int64
to accommodate large bit shift operations that exceed 32 bits.
This fixes overflow errors when building for GOOS=openbsd GOARCH=arm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant