-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
encoding/binary: Read fails to detect a non-pointer 'data' argument #32927
Comments
CC @griesemer for |
Looks like
|
Change https://golang.org/cl/184957 mentions this issue: |
It is not clear to me that the CL chose the right approach. Given that the Read function panics when other conditions that must be satisfied are not satisfied, it seems ok to panic in this case as well. Marked as NeedsDecision. |
My point is that in the case when a pointer to a struct is passed and struct itself is incorrect then the reflect-related code may (or may not?) panic. |
I think we should do the same thing we do in the fallback case, which is if size < 0 {
return errors.New("binary.Read: invalid type " + reflect.TypeOf(data).String())
} |
Shouldn't the behaviour be equal to other packages? Both encoding/json and encoding/xml is returning error. |
encoding/json and encoding/xml with int32 instead of struct{} : https://play.golang.org/p/KKE6ssLsBmy |
Hello @griesemer, I am just prodding you about this issue. From the precedent, it seems to be that returning an error is alright. This issue is marked for Go1.14 and there is already a CL that's just waiting for your blessing https://go-review.googlesource.com/c/go/+/184957/, please take a look and thank you. |
@odeke-em Thanks. On it. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It does on play.golang.org
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I was trying to read a value with binary.Read. That function need a pointer for the Data parameter. I was using that function faulty by passing a non pointer value to it.
https://play.golang.org/p/ZFNQ4PjM9H-
What did you expect to see?
An error message saying that Data need to be a pointer
What did you see instead?
No error and and my value was zero. The method doesn't do anything at all.
The text was updated successfully, but these errors were encountered: