Return error for non-finite float32 in Marshal, matching float64 - #597
Open
binggao1230 wants to merge 1 commit into
Open
Return error for non-finite float32 in Marshal, matching float64#597binggao1230 wants to merge 1 commit into
binggao1230 wants to merge 1 commit into
Conversation
Marshaling a float32 Inf/NaN emitted the literal bytes +Inf/-Inf/NaN with a nil error, which is invalid JSON. encoding/json and the existing float64 opcodes return *UnsupportedValueError instead; the float32 opcodes never got the guard. Mirror the float64 Inf/NaN check onto every float32 opcode in the VM template and regenerate the four vm variants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
json.Marshal(float32(math.Inf(1)))returns the bytes+Infwith a nil error, which is invalid JSON.encoding/jsonand go-json's own float64 opcodes return*UnsupportedValueErrorfor non-finite floats (RFC 8259 numbers can't represent Inf/NaN); the float32 opcodes never carried the guard.The Inf/NaN check lives in the VM opcode template (
internal/cmd/generator/vm.go.tmpl): every float64 opcode has it, no float32 opcode did. This mirrors it onto the float32 opcode family and regenerates the four vm variants, so bare/pointer/struct/slice/map float32 values are covered across plain, indent, color and color+indent output.Tests assert float32 Inf/-Inf/NaN now return
*UnsupportedValueErrorwith no output, matchingencoding/jsonand the existing float64 behaviour, while finite float32 still marshals unchanged.