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

Can't correctly append bytes bigger than 0x79 #1749

Closed
alexvanin opened this issue Feb 16, 2021 · 0 comments · Fixed by #1750
Closed

Can't correctly append bytes bigger than 0x79 #1749

alexvanin opened this issue Feb 16, 2021 · 0 comments · Fixed by #1750
Assignees
Labels
bug Something isn't working
Milestone

Comments

@alexvanin
Copy link
Contributor

When appending single bytes to []byte, compiler adds extra 0x0 for all values starting from 0x80 up to 0xFF

	{
		"append bytes bigger than 0x79",
		`package foo
		func Main() []byte {
			var z []byte
			z = append(z, 0x78, 0x79, 0x80, 0x81, 0xFF)
			return z
		}`,
		[]byte{0x78, 0x79, 0x80, 0x81, 0xFF},
	},

// Expected :[]byte{0x78, 0x79, 0x80, 0x81, 0xff}
// Actual   :[]byte{0x78, 0x79, 0x80, 0x0, 0x81, 0x0, 0xff, 0x0}

Appending with z = append(z, []byte{0x78, 0x79, 0x80, 0x81, 0xFF}...) solves the issue.

@roman-khimov roman-khimov added the bug Something isn't working label Feb 16, 2021
@roman-khimov roman-khimov added this to the v0.94.0 milestone Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants