Commit 5a2c275b authored by Shenghou Ma's avatar Shenghou Ma

fmt, encoding/gob: fix misuse of Read

reader.Read() can return both 0,nil and len(buf),err.
To be safe, we use io.ReadFull instead of doing reader.Read directly.

Fixes #3472.

R=bradfitz, rsc, ality
CC=golang-dev
https://golang.org/cl/6285050
parent 2ad67147
......@@ -62,15 +62,15 @@ func overflow(name string) error {
// Used only by the Decoder to read the message length.
func decodeUintReader(r io.Reader, buf []byte) (x uint64, width int, err error) {
width = 1
_, err = r.Read(buf[0:width])
if err != nil {
n, err := io.ReadFull(r, buf[0:width])
if n == 0 {
return
}
b := buf[0]
if b <= 0x7f {
return uint64(b), width, nil
}
n := -int(int8(b))
n = -int(int8(b))
if n > uint64Size {
err = errBadUint
return
......
......@@ -337,7 +337,10 @@ func (r *readRune) readByte() (b byte, err error) {
r.pending--
return
}
_, err = r.reader.Read(r.pendBuf[0:1])
n, err := io.ReadFull(r.reader, r.pendBuf[0:1])
if n != 1 {
return 0, err
}
return r.pendBuf[0], err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment