clean up EOF

R=rsc
DELTA=5  (0 added, 1 deleted, 4 changed)
OCL=32465
CL=32467
This commit is contained in:
Rob Pike 2009-07-29 15:24:42 -07:00
parent 1ff5897d64
commit 1fc0960fb4
2 changed files with 4 additions and 5 deletions

View File

@ -79,10 +79,9 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
var n int;
n, dec.state.err = io.ReadFull(dec.r, dec.buf[0:nbytes]);
if dec.state.err != nil {
break;
}
if n < int(nbytes) {
dec.state.err = io.ErrUnexpectedEOF;
if dec.state.err == os.EOF {
dec.state.err = io.ErrUnexpectedEOF;
}
break;
}

View File

@ -240,7 +240,7 @@ func corruptDataCheck(s string, err os.Error, t *testing.T) {
// Check that we survive bad data.
func TestBadData(t *testing.T) {
corruptDataCheck("\x01\x01\x01", os.EOF, t);
corruptDataCheck("", os.EOF, t);
corruptDataCheck("\x7Fhi", io.ErrUnexpectedEOF, t);
corruptDataCheck("\x03now is the time for all good men", errBadType, t);
}