Skip to content
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

Building for linux-386 is failing with error math.MaxUint32 (untyped int constant 4294967295) overflows int #1960

Open
vivek-yadav opened this issue Feb 21, 2025 · 0 comments

Comments

@vivek-yadav
Copy link

In Go, the math.MaxUint32 constant is an untyped integer constant that defaults to type int in contexts where a typed value is required. On a 32-bit architecture like linux-386, the int type is 32-bit signed, and math.MaxUint32 (which is 4294967295) exceeds the maximum value that can be represented by a 32-bit signed integer, causing an overflow error.

When building for Linux 32bit - linux-386 platform, I am getting this error:
github.com/valyala/[email protected]/tcplisten/tcplisten.go:187:9: math.MaxUint32 (untyped int constant 4294967295) overflows int

This change:
https://github.com/valyala/fasthttp/pull/1929/files#diff-7736b8b9d7fd04be372c289a070fe0dbc9b6f16c3a6ee6ed1dcf5861c27f7546

if i > math.MaxUint32 {
	return 0, errors.New("value exceeds uint32 max value")
}

It is blocking a lot of my services and CLI from building as I have pipeline for linux-386 also.

To avoid this error, you can explicitly convert math.MaxUint32 to an unsigned integer type like uint32 when using it in comparisons or assignments. This ensures that the constant is treated as an unsigned integer, which can handle the full range of MaxUint32 without overflow.

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

No branches or pull requests

1 participant