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

misleading signature of encoding/binary.BigEndian.PutUint32() #35943

Closed
Vany opened this issue Dec 3, 2019 · 1 comment
Closed

misleading signature of encoding/binary.BigEndian.PutUint32() #35943

Vany opened this issue Dec 3, 2019 · 1 comment

Comments

@Vany
Copy link

Vany commented Dec 3, 2019

Hello!
Seems like func (bigEndian) PutUint32(b []byte, v uint32) works with byte slices, but inside it requires this slice be at least 4 elements in size.
So, this signature allow me to put empty slice here and have panic because there is no checks inside.

I propose to change this []byte to [4]byte to make this misleading signature more demanding.

@ianlancetaylor
Copy link
Contributor

Thanks for the note, but we can't make that change. It would break the Go 1 compatibility guarantee (https://golang.org/doc/go1compat).

In any case it's routine in Go for a function to expect a slice to be large enough for the operation.

@golang golang locked and limited conversation to collaborators Dec 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants