Repository navigation
fix(read): don't return the clamped value for an out of range int64 - #233
Conversation
tryInt64 recorded the ParseInt range error but returned the clamped MaxInt64/MinInt64, so Int64 and (on 64-bit) Int returned it, while Uint resets the value to 0 since 87608e8 and Int returns 0 on 32-bit.
Ekko82
left a comment
There was a problem hiding this comment.
go test . -run '^Test(Int|Uint)' -count=1 passes at c9b0427 on Windows with Go 1.27.1 for both amd64 and 386. This includes the full-range Int64 regressions from #228, so valid values beyond the 32-bit int range remain intact.
I also ran the new overflow test against the base read.go on amd64: both cases fail with the clamped extrema. They pass at this head, returning zero and recording the parse error. Local validation covered the numeric-reader tests; I did not run the full suite.
Float returned the clamped +Inf/-Inf of strconv.ParseFloat with the range error recorded, while tryInt64 (#233) and tryUint reset the value to 0 and Int returns 0 on 32-bit. Do the same here; a non-numeric value was already 0.
|
Landed as merge commit \4c215a7. The test insertion conflicted with \5e44dc9, which added \TestIntsIntMapParseEnv\ right after \TestInt64FullRange; the merge keeps both tests and the suite is green (amd64 full suite + GOARCH=386 numeric tests). Thanks for the fix, and to @Ekko82 for the Windows/386 verification. |
tryInt64records thestrconv.ParseIntrange error but keeps the clamped value, so an out of range string comes back asMaxInt64/MinInt64:tryUintalready resets the value to 0 on error since 87608e8 ("don't return the clamped max value"), andIntreturns 0 when the value is outside the int range on 32-bit, so this does the same intryInt64. In-range values and non-numeric strings (which already gave 0) are unchanged.TestInt64OutOfRangecovers both ends and fails without the change.go test -race ./...(withNAMEunset),GOARCH=386 go test -run 'TestInt|TestUint'andgo vetpass locally.Written with AI assistance (Claude); I have reviewed the change.