mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes.Buffer: restore panic on out-of-memory
Make the panic detectable, and use that in ioutil.ReadFile to give an error if the file is too big. R=golang-dev, minux.ma, bradfitz CC=golang-dev https://golang.org/cl/5563045
This commit is contained in:
parent
4d3b9d9757
commit
b0d2713b77
3 changed files with 35 additions and 22 deletions
|
|
@ -392,13 +392,18 @@ func TestHuge(t *testing.T) {
|
|||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
// We expect a panic.
|
||||
defer func() {
|
||||
if err, ok := recover().(error); ok && err == ErrTooLarge {
|
||||
return
|
||||
} else {
|
||||
t.Error(`expected "too large" error; got`, err)
|
||||
}
|
||||
}()
|
||||
b := new(Buffer)
|
||||
big := make([]byte, 500e6)
|
||||
for i := 0; i < 1000; i++ {
|
||||
if _, err := b.Write(big); err != nil {
|
||||
// Got error as expected. Stop
|
||||
return
|
||||
}
|
||||
b.Write(big)
|
||||
}
|
||||
t.Error("error expected")
|
||||
t.Error("panic expected")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue