-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: int overflow for 32 bit machines #2135
Conversation
Closes celestiaorg#2129 celestiaorg#2121 didn't actually fix the issue because the expression ```go NanosecondsPerYear = int64(NanosecondsPerSecond * SecondsPerYear) ``` was multiplying two `int`s together prior to the cast to `int64`. Since the product of those two `int`s overflows an `int32`, the value would overflow prior to the cast. The fix proposed in this PR converts SecondsPerYear to an `int64`. Now the expression multiplies an `int` and `int64` so the product is an `int64` which won't overflow. ## Testing I added this to the Makefile ```go ## build-arm: Build the celestia-appd binary into the ./build directory. Target the linux OS and ARM (32-bit) architecture. build-arm: mod @cd ./cmd/celestia-appd @mkdir -p build/ @Goos=linux GOARCH=arm go build $(BUILD_FLAGS) -o build/ ./cmd/celestia-appd @go mod tidy -compat=1.20 .PHONY: build-arm ``` Before ```shell $ make build-arm --> Updating go.mod # github.com/celestiaorg/celestia-app/x/mint/types x/mint/types/constants.go:15:29: NanosecondsPerSecond * SecondsPerYear (constant 31556952000000000 of type int) overflows int make: *** [build-arm] Error 1 ``` After ```shell $ make build-arm --> Updating go.mod ```
Nick is running into this error on an android, I'd imagine maybe the |
You're right the celestia-node Makefile doesn't have a If celestia-node, I think we should open an issue in celestia-node repo. |
Circling back on this for visibility @jcstein:
If ya'll still observe this error on celestia-node releases that should work, can you please open a new GH issue? |
hey @rootulp thanks for following up here. i don’t think an issue is needed, and will see if one of the newer versions works! |
assuming it doesn’t happen on a release where it is fixed |
Closes #2129
#2121 didn't actually fix the issue because the expression
was multiplying two
int
s together prior to the cast toint64
. Since the product of those twoint
s overflows anint32
, the value would overflow prior to the cast.The fix proposed in this PR converts SecondsPerYear to an
int64
. Now the expression multiplies anint
andint64
so the product is anint64
which won't overflow.Testing
I added this to the Makefile
Before
After
$ make build-arm --> Updating go.mod