2012-02-16 21:49:59 -07:00
|
|
|
// run
|
2010-05-01 14:15:42 -06:00
|
|
|
|
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-02-06 05:44:39 -07:00
|
|
|
// http://golang.org/issue/589
|
2010-05-01 14:15:42 -06:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
var bug = false
|
|
|
|
|
|
|
|
var minus1 = -1
|
2012-12-04 17:51:51 -07:00
|
|
|
var five = 5
|
2010-05-01 14:15:42 -06:00
|
|
|
var big int64 = 10 | 1<<32
|
|
|
|
|
2012-09-23 22:06:41 -06:00
|
|
|
type block [1<<19]byte
|
|
|
|
|
|
|
|
var g1 []block
|
2010-09-01 14:40:20 -06:00
|
|
|
|
2010-05-01 14:15:42 -06:00
|
|
|
func shouldfail(f func(), desc string) {
|
|
|
|
defer func() { recover() }()
|
|
|
|
f()
|
|
|
|
if !bug {
|
|
|
|
println("BUG")
|
|
|
|
bug = true
|
|
|
|
}
|
|
|
|
println("didn't crash: ", desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func badlen() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g1 = make([]block, minus1)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func biglen() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g1 = make([]block, big)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func badcap() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g1 = make([]block, 10, minus1)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func badcap1() {
|
2012-12-04 17:51:51 -07:00
|
|
|
g1 = make([]block, 10, five)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func bigcap() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g1 = make([]block, 10, big)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
2012-09-23 22:06:41 -06:00
|
|
|
var g3 map[block]block
|
2010-05-01 14:15:42 -06:00
|
|
|
func badmapcap() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g3 = make(map[block]block, minus1)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func bigmapcap() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g3 = make(map[block]block, big)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
2012-09-23 22:06:41 -06:00
|
|
|
type cblock [1<<16-1]byte
|
|
|
|
|
|
|
|
var g4 chan cblock
|
2010-05-01 14:15:42 -06:00
|
|
|
func badchancap() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g4 = make(chan cblock, minus1)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func bigchancap() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g4 = make(chan cblock, big)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func overflowchan() {
|
2012-09-23 22:06:41 -06:00
|
|
|
g4 = make(chan cblock, 1<<30)
|
2010-05-01 14:15:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
shouldfail(badlen, "badlen")
|
|
|
|
shouldfail(biglen, "biglen")
|
|
|
|
shouldfail(badcap, "badcap")
|
|
|
|
shouldfail(badcap1, "badcap1")
|
|
|
|
shouldfail(bigcap, "bigcap")
|
|
|
|
shouldfail(badmapcap, "badmapcap")
|
|
|
|
shouldfail(bigmapcap, "bigmapcap")
|
|
|
|
shouldfail(badchancap, "badchancap")
|
|
|
|
shouldfail(bigchancap, "bigchancap")
|
|
|
|
shouldfail(overflowchan, "overflowchan")
|
|
|
|
}
|