From: Rob Pike Date: Sat, 12 Dec 2009 20:27:43 +0000 (+1100) Subject: fix bug for large counts: used a one-byte buffer. X-Git-Tag: weekly.2009-12-22~79 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=687777710bb5c8120ccecbce6e70097c3736f094;p=gostls13.git fix bug for large counts: used a one-byte buffer. R=rsc CC=golang-dev https://golang.org/cl/174082 --- diff --git a/src/pkg/gob/decoder.go b/src/pkg/gob/decoder.go index a88c97400e..5202c82856 100644 --- a/src/pkg/gob/decoder.go +++ b/src/pkg/gob/decoder.go @@ -23,7 +23,7 @@ type Decoder struct { state *decodeState; // reads data from in-memory buffer countState *decodeState; // reads counts from wire buf []byte; - oneByte []byte; + countBuf [9]byte; // counts may be uint64s (unlikely!), require 9 bytes } // NewDecoder returns a new decoder that reads from the io.Reader. @@ -34,7 +34,6 @@ func NewDecoder(r io.Reader) *Decoder { dec.state = newDecodeState(nil); // buffer set in Decode(); rest is unimportant dec.decoderCache = make(map[reflect.Type]map[typeId]**decEngine); dec.ignorerCache = make(map[typeId]**decEngine); - dec.oneByte = make([]byte, 1); return dec; } @@ -73,7 +72,7 @@ func (dec *Decoder) Decode(e interface{}) os.Error { for { // Read a count. var nbytes uint64; - nbytes, dec.state.err = decodeUintReader(dec.r, dec.oneByte); + nbytes, dec.state.err = decodeUintReader(dec.r, dec.countBuf[0:]); if dec.state.err != nil { break }