Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding anonymous struct with multiple fields on 32-bit systems #374

Merged
merged 1 commit into from
Jan 12, 2023

Conversation

saracen
Copy link
Contributor

@saracen saracen commented Jan 10, 2023

This fixes another 32-bit edge case, which would result in the last field of an anonymous struct being duplicated for every other field within that same struct when encoded.

The fix requires a slice to be copied, which is only needed on 32-bit systems. An existing fix was done for fieldsDirect, but this expands to using the copied slice for fieldsSub too.

I've added a test case that captures the failure.

On Linux, executing GOARCH=386 go test -run TestEncodeAnonymousStruct without the changes done in encode.go results in:

--- FAIL: TestEncodeAnonymousStruct (0.00s)
    --- FAIL: TestEncodeAnonymousStruct/embedded_anonymous_multiple_fields (0.00s)
        encode_test.go:373:
            have:
                [Inner2]
                  N = 4

                [Inner2]
                  N = 4
            want:
                [Inner1]
                  N = 3

                [Inner2]
                  N = 4

With the changes, it works as expected.

@arp242 arp242 merged commit 08a2344 into BurntSushi:master Jan 12, 2023
@saracen
Copy link
Contributor Author

saracen commented Jan 31, 2023

@arp242 Thank you for merging. Do you know when there will be a tagged release with this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants