mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
0796c1c3ec
commit
696bf79350
2 changed files with 52 additions and 4 deletions
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue