<p dir="auto">There are two copes of <code class="notranslate">Biobuf</code> in the compiler, <code class="notranslate">cmd/internal/obj/util.go</code> and <code class="notranslate">cmd/internal/ld/util.go</code>. Both are in various stages of decomposition, for example <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/golang/go/commit/05d53165cebf7c31c4b4c2c818650b2efceefbeb/hovercard" href="https://github.com/golang/go/commit/05d53165cebf7c31c4b4c2c818650b2efceefbeb"><tt>05d5316</tt></a> was applied to the latter, but not the former. The former has sort of had <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/golang/go/commit/05d53165cebf7c31c4b4c2c818650b2efceefbeb/hovercard" href="https://github.com/golang/go/commit/05d53165cebf7c31c4b4c2c818650b2efceefbeb"><tt>05d5316</tt></a> applied accidentally, and now <code class="notranslate">Bungetc</code> is inconsistent, some methods check the unget buffer, others do not.</p>
<ul dir="auto">
<li>If there must be a wrapper around <code class="notranslate">bufio.Buffer</code>, then there should be at most one in the compiler.</li>
<li>Preferably we should be using <code class="notranslate">bufio.Buffer</code> directly everywhere.</li>
</ul>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rsc/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rsc">@rsc</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/robpike/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/robpike">@robpike</a> thoughts ?</p>
<p dir="auto">by <strong>james.fang.cn</strong>:</p>
<pre class="notranslate">What does 'go version' print?
go version go1.2.1 linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.
see attachment program.


What happened?
1)length of buffer is 2 instead of 1
2)binary.Read panic with
panic: reflect: reflect.Value.SetInt using value obtained using unexported field

What should have happened instead?
skip lower-case field of struct, encoded buffer length is 1,
no panic when decode.

Please provide any additional information below.
maybe the following conditions in binary.go not quite right?

if v := v.Field(i); v.CanSet() || t.Field(i).Name != "_" {

v.CanSet will be false for lower-case field, but name is not "_", so it's not
skipped.</pre>
<p dir="auto">Attachments:</p>
<ol dir="auto">
<li><a href="https://storage.googleapis.com/go-attachment/8315/0/encoding_binary_bug.go" rel="nofollow">encoding_binary_bug.go</a> (326 bytes)</li>
</ol>