Skip to content

Commit

Permalink
reflect: panic if MakeSlice is given bad len/cap arguments.
Browse files Browse the repository at this point in the history
Fixes #3330.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5847043
  • Loading branch information
dsymonds committed Mar 16, 2012
1 parent 8009542 commit 11cc5a2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pkg/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,15 @@ func MakeSlice(typ Type, len, cap int) Value {
if typ.Kind() != Slice {
panic("reflect.MakeSlice of non-slice type")
}
if len < 0 {
panic("reflect.MakeSlice: negative len")
}
if cap < 0 {
panic("reflect.MakeSlice: negative cap")
}
if len > cap {
panic("reflect.MakeSlice: len > cap")
}

// Declare slice so that gc can see the base pointer in it.
var x []byte
Expand Down

0 comments on commit 11cc5a2

Please sign in to comment.