aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/io
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-02-01 19:26:59 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-02-01 19:26:59 +0000
commit9af4cb9545ce481b8d9d4a13acfe26512032e21b (patch)
tree7e7e6083ebe59999943a211a17f8ef6f07f17c2f /libgo/go/io
parent6b6cd722f329a168f98d1f421834cf40bb33a77d (diff)
downloadgcc-9af4cb9545ce481b8d9d4a13acfe26512032e21b.zip
gcc-9af4cb9545ce481b8d9d4a13acfe26512032e21b.tar.gz
gcc-9af4cb9545ce481b8d9d4a13acfe26512032e21b.tar.bz2
libgo: Update to weekly.2012-01-27.
From-SVN: r183810
Diffstat (limited to 'libgo/go/io')
-rw-r--r--libgo/go/io/ioutil/ioutil.go17
1 files changed, 15 insertions, 2 deletions
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
}