Russ Cox | 96b9064 | 2008-09-12 09:43:21 -0700 | [diff] [blame] | 1 | // $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: should not crash |
| 2 | |
| 3 | // Copyright 2009 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 | package main |
| 8 | |
| 9 | func main() { |
| 10 | var b [0]byte; |
Russ Cox | e2bf227 | 2009-04-16 23:07:15 -0700 | [diff] [blame] | 11 | s := string(&b); // out of bounds trap |
Russ Cox | 5383e28 | 2008-09-22 20:12:15 -0700 | [diff] [blame] | 12 | if s != "" { |
| 13 | panic("bad convert") |
| 14 | } |
Russ Cox | be2edb5 | 2009-03-03 08:39:12 -0800 | [diff] [blame] | 15 | var b1 = [5]byte{'h', 'e', 'l', 'l', 'o'}; |
Russ Cox | e2bf227 | 2009-04-16 23:07:15 -0700 | [diff] [blame] | 16 | if string(&b1) != "hello" { |
Russ Cox | 5383e28 | 2008-09-22 20:12:15 -0700 | [diff] [blame] | 17 | panic("bad convert 1") |
| 18 | } |
Russ Cox | 5564504 | 2009-01-06 15:19:02 -0800 | [diff] [blame] | 19 | var b2 = make([]byte, 5); |
Russ Cox | 5383e28 | 2008-09-22 20:12:15 -0700 | [diff] [blame] | 20 | for i := 0; i < 5; i++ { b2[i] = b1[i] } |
| 21 | if string(b2) != "hello" { |
| 22 | panic("bad convert 2") |
| 23 | } |
Russ Cox | 96b9064 | 2008-09-12 09:43:21 -0700 | [diff] [blame] | 24 | } |
| 25 | |