summaryrefslogtreecommitdiff
path: root/libgo/go/io
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-02-01 19:26:59 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-02-01 19:26:59 +0000
commit86babf4bfda7c2c2e9be4abc20e4d8073e05e5be (patch)
tree7e7e6083ebe59999943a211a17f8ef6f07f17c2f /libgo/go/io
parentdf9ff8bf53f716508a120d15cc144e628fd2e9b5 (diff)
downloadgcc-86babf4bfda7c2c2e9be4abc20e4d8073e05e5be.tar.gz
libgo: Update to weekly.2012-01-27.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183810 138bc75d-0d04-0410-961f-82ee72b054a4
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 65f4b3ac2e5..cbe1a5839df 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
}