...
Run Format

Source file test/fixedbugs/bug273.go

Documentation: test/fixedbugs

     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  type cblock [1<<16-1]byte
    52  
    53  var g4 chan cblock
    54  func badchancap() {
    55  	g4 = make(chan cblock, minus1)
    56  }
    57  
    58  func bigchancap() {
    59  	g4 = make(chan cblock, big)
    60  }
    61  
    62  func overflowchan() {
    63  	g4 = make(chan cblock, 1<<30)
    64  }
    65  
    66  func main() {
    67  	shouldfail(badlen, "badlen")
    68  	shouldfail(biglen, "biglen")
    69  	shouldfail(badcap, "badcap")
    70  	shouldfail(badcap1, "badcap1")
    71  	shouldfail(bigcap, "bigcap")
    72  	shouldfail(badchancap, "badchancap")
    73  	shouldfail(bigchancap, "bigchancap")
    74  	shouldfail(overflowchan, "overflowchan")
    75  }
    76  

View as plain text