diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-03 09:24:10 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-03 09:24:10 +0000 |
commit | a68d233ff64d692c5376bf8fc84c6edb4a17e6a7 (patch) | |
tree | 31998253493902e174563585be32c732f581fbe8 /libgo/go/io/ioutil | |
parent | ef91be55fa1a0f1f2e3a483c39a8768c1a4c1e58 (diff) | |
download | gcc-a68d233ff64d692c5376bf8fc84c6edb4a17e6a7.tar.gz |
2012-02-03 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 183862 using svnmerge
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@183866 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/io/ioutil')
-rw-r--r-- | libgo/go/io/ioutil/ioutil.go | 17 |
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 } |