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

Most upvoted comments

Thanks, I can confirm all tests pass again with the latest commit.