bytes.Buffer: turn buffer size overflows into errors

Fixes #2743.

R=golang-dev, gri, r
CC=golang-dev
https://golang.org/cl/5556072
This commit is contained in:
Rob Pike 2012-01-20 13:51:49 -08:00
parent 0796c1c3ec
commit 696bf79350
2 changed files with 52 additions and 4 deletions

View file

@ -386,3 +386,19 @@ func TestReadEmptyAtEOF(t *testing.T) {
t.Errorf("wrong count; got %d want 0", n)
}
}
func TestHuge(t *testing.T) {
// About to use tons of memory, so avoid for simple installation testing.
if testing.Short() {
return
}
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
}
}
t.Error("error expected")
}