1 // run 2 3 // Copyright 2010 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // https://golang.org/issue/589 8 9 package main 10 11 var bug = false 12 13 var minus1 = -1 14 var five = 5 15 var big int64 = 10 | 1<<32 16 17 type block [1<<19]byte 18 19 var g1 []block 20 21 func shouldfail(f func(), desc string) { 22 defer func() { recover() }() 23 f() 24 if !bug { 25 println("BUG") 26 bug = true 27 } 28 println("didn't crash: ", desc) 29 } 30 31 func badlen() { 32 g1 = make([]block, minus1) 33 } 34 35 func biglen() { 36 g1 = make([]block, big) 37 } 38 39 func badcap() { 40 g1 = make([]block, 10, minus1) 41 } 42 43 func badcap1() { 44 g1 = make([]block, 10, five) 45 } 46 47 func bigcap() { 48 g1 = make([]block, 10, big) 49 } 50 51 var g3 map[block]block 52 func badmapcap() { 53 g3 = make(map[block]block, minus1) 54 } 55 56 func bigmapcap() { 57 g3 = make(map[block]block, big) 58 } 59 60 type cblock [1<<16-1]byte 61 62 var g4 chan cblock 63 func badchancap() { 64 g4 = make(chan cblock, minus1) 65 } 66 67 func bigchancap() { 68 g4 = make(chan cblock, big) 69 } 70 71 func overflowchan() { 72 g4 = make(chan cblock, 1<<30) 73 } 74 75 func main() { 76 shouldfail(badlen, "badlen") 77 shouldfail(biglen, "biglen") 78 shouldfail(badcap, "badcap") 79 shouldfail(badcap1, "badcap1") 80 shouldfail(bigcap, "bigcap") 81 shouldfail(badmapcap, "badmapcap") 82 shouldfail(bigmapcap, "bigmapcap") 83 shouldfail(badchancap, "badchancap") 84 shouldfail(bigchancap, "bigchancap") 85 shouldfail(overflowchan, "overflowchan") 86 } 87