gojq: int(math.Inf(1)) in funcOpMul is incorrect
This was caught out by a test failure on mips64:
--- FAIL: TestCliRun (0.86s)
--- FAIL: TestCliRun/multiply_strings (0.00s)
cli_test.go:87: standard output:
(
"""
... // 8 identical lines
"abcabc"
null
- null
+ ""
"""
)
FAIL
FAIL github.com/itchyny/gojq/cli 0.872s
The result of int(math.Inf(1))
1 depends on the architecture, and is not correct in general to do.
On s390x / ppc64le (big-endian), it returns 9223372036854775807, which would have failed as well, would it not be for the limit condition.
A simple way to fix this is to check:
math.IsNaN(cnt - cnt)
Which catches both infinite (positive / negative) as well as NaN
.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (13 by maintainers)
Commits related to this issue
- fix multiplying strings by infinite Relying on the result of int(math.Inf(1) is not correct as it's not guaranteed to give an expected result, which depends on the platform. mips64 (softfloat): 0 pp... — committed to Ikke/gojq by Ikke 3 years ago
- testing/gojq: fix issue with 'infinite' Issue report upstream: https://github.com/itchyny/gojq/issues/69 — committed to alpinelinux/aports by Ikke 3 years ago
- fix multiplying strings by infinite Relying on the result of `int(math.Inf(1))` is not correct as it's not guaranteed to give an expected result, which depends on the platform. mips64 (softfloat): 0... — committed to Ikke/gojq by Ikke 3 years ago
Thanks, I can confirm all tests pass again with the latest commit.