Test failures on 32bit systems
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4k
- Forks
- 337
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
It looks like v1.9.0 increased test coverage, and on 32bit systems (like armhf), the int and uint tests fail because those types are too small to hold some of the values:
--- FAIL: TestNumber/int64/#14/Value/Pointer/ToE (0.01s)
number_test.go:381:
error:
got non-nil error
got:
e`unable to cast "9223372036854775807" of type string to int64: strconv.ParseInt: parsing "9223372036854775807": value out of range`
stack:
/home/gibmat/cast/number_test.go:381
c.Assert(err, qt.IsNil)
--- FAIL: TestNumber/uint64/#14/Value/Pointer/ToTypeE (0.01s)
number_test.go:367:
error:
got non-nil error
got:
e`unable to cast "18446744073709551615" of type string to uint64: strconv.ParseUint: parsing "18446744073709551615": value out of range`
stack:
/home/gibmat/cast/number_test.go:367
c.Assert(err, qt.IsNil)
I looked at the code, and explicitly telling strconv.Parse{Int,Uint} to use a full 64bit variable allows the tests to pass on both 32bit and 64bit systems. However, I don't know if this might have other consequence if trying to cast an 8, 16, or 32bit variable.
diff --git a/number.go b/number.go
index a58dc4d..a4c4576 100644
--- a/number.go
+++ b/number.go
@@ -405,7 +405,7 @@ func parseNumber[T Number](s string) (T, error) {
}
func parseInt[T integer](s string) (T, error) {
- v, err := strconv.ParseInt(trimDecimal(s), 0, 0)
+ v, err := strconv.ParseInt(trimDecimal(s), 0, 64)
if err != nil {
return 0, err
}
@@ -414,7 +414,7 @@ func parseInt[T integer](s string) (T, error) {
}
func parseUint[T unsigned](s string) (T, error) {
- v, err := strconv.ParseUint(strings.TrimLeft(trimDecimal(s), "+"), 0, 0)
+ v, err := strconv.ParseUint(strings.TrimLeft(trimDecimal(s), "+"), 0, 64)
if err != nil {
return 0, err
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with parseInt and parseUint in number.go, then inspect the failing cases around lines 367 and 381 in number_test.go. Check the behavior on 32-bit and 64-bit systems, including casts to narrower integer types. Done means the reported int64 and uint64 cases pass without breaking expected overflow handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100