Skip to content

'%g' % 0 causes Overflow #554

Description

@mark-rushakoff

I have been chasing down a bug in my code that I thought had to do with a recursive object, but now I have reduced the problem to %g formatting being unable to render a 0.

I have checked out go-jsonnet at commit 51daeb3 (current master).

$ go version
go version go1.16.5 darwin/amd64

$ echo '"%f" % 0' | go run ./cmd/jsonnet - # %f works correctly
"0.000000"

$ echo '"%g" % 0' | go run ./cmd/jsonnet -
RUNTIME ERROR: Overflow
	<std>:648:38-59	thunk from <thunk <exponent> from <function <format_code>>>
	<std>:648:28-74	thunk <exponent> from <function <format_code>>
	<std>:649:14-22	function <format_code>
	<std>:722:15-60	thunk <s> from <function <format_codes_arr>>
	<std>:727:24-25	thunk from <thunk <s_padded> from <function <format_codes_arr>>>
	<std>:480:30-33	thunk from <thunk from <function <pad_left>>>
	<std>:480:19-34	thunk from <function <pad_left>>
	<std>:476:11-12	thunk from <function <padding>>
	<std>:472:12-13	function <aux>
	<std>:476:7-17	function <padding>
	<std>:480:7-38	function <pad_left>
	<std>:727:15-39	thunk <s_padded> from <function <format_codes_arr>>
	<std>:733:55-63	thunk from <function <format_codes_arr>>
	<std>:733:11-64	function <format_codes_arr>
	<std>:781:7-48	function <anonymous>
	<std>:237:7-23	function <anonymous>
	<stdin>:1:1-9
	During evaluation

exit status 1

I have confirmed that this behavior is present at least as far back as v0.13.0 of go-jsonnet, but I didn't check any older revisions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions