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

encoding/binary: should reject int, float #1201

Closed
gopherbot opened this issue Oct 14, 2010 · 4 comments
Closed

encoding/binary: should reject int, float #1201

gopherbot opened this issue Oct 14, 2010 · 4 comments

Comments

@gopherbot
Copy link

by thomas.e.zander:

What steps will reproduce the problem?
1. Compile and run the following demo program:

package main
import (
       "os"
       "encoding/binary"
)
type DemoType struct {
       x,y int
}
func main() {
       x := DemoType{1,2}
       fd, _ := os.Open("demofile.bin", os.O_RDWR|os.O_CREAT, 0600)
       defer fd.Close()
       binary.Write(fd, binary.LittleEndian, x)
}

What is the expected output?
I would expect the compiler to bail out and report an error since the size of 'int' is
not defined in the language standard. Therefore, the written output would be
compiler/architecture dependent. The same applies to using the 'float' type in the
struct.
Instead, the compiler could print an error that it expects the size of the used data
types to be of fixed width (int32, int64, float32 etc.).

What do you see instead?
Program compiles fine. It outputs a file containing 8 zero-valued bytes.

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g on Linux
6g on Mac OS X

Which operating system are you using?
Linux (8g)
Mac OS X (6g)

Which revision are you using?  (hg identify)
25631
@rsc
Copy link
Contributor

rsc commented Oct 14, 2010

Comment 1:

Looks like a bug introduced when we changed the way reflect works.

Owner changed to r...@golang.org.

Status changed to Started.

@gopherbot
Copy link
Author

Comment 3 by pgavlin:

I have a couple of fixes for this issue--the first is localized to encoding/binary, the
second involves some changes to gc, ld, runtime, and reflect.  Is it worth submitting a
CL for either of these, and if so, which one?  I've included patches for either fix in
the attached tarball.

Attachments:

  1. issue1201.tar (7168 bytes)

@rsc
Copy link
Contributor

rsc commented Jan 2, 2011

Comment 4:

The fix should be one or two lines in encoding/binary.

@rsc
Copy link
Contributor

rsc commented Jan 4, 2011

Comment 5:

This issue was closed by revision 236f963.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
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

2 participants