From 9af4cb9545ce481b8d9d4a13acfe26512032e21b Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 1 Feb 2012 19:26:59 +0000 Subject: libgo: Update to weekly.2012-01-27. From-SVN: r183810 --- libgo/go/io/ioutil/ioutil.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'libgo/go/io') diff --git a/libgo/go/io/ioutil/ioutil.go b/libgo/go/io/ioutil/ioutil.go index 65f4b3a..cbe1a58 100644 --- a/libgo/go/io/ioutil/ioutil.go +++ b/libgo/go/io/ioutil/ioutil.go @@ -14,9 +14,22 @@ import ( // readAll reads from r until an error or EOF and returns the data it read // from the internal buffer allocated with a specified capacity. -func readAll(r io.Reader, capacity int64) ([]byte, error) { +func readAll(r io.Reader, capacity int64) (b []byte, err error) { buf := bytes.NewBuffer(make([]byte, 0, capacity)) - _, err := buf.ReadFrom(r) + // If the buffer overflows, we will get bytes.ErrTooLarge. + // Return that as an error. Any other panic remains. + defer func() { + e := recover() + if e == nil { + return + } + if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge { + err = panicErr + } else { + panic(e) + } + }() + _, err = buf.ReadFrom(r) return buf.Bytes(), err } -- cgit v1.1