blob: 92163baa1c15e542a547f65c9725232598bcb38a [file] [log] [blame]
Russ Cox96b90642008-09-12 09:43:21 -07001// $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
7package main
8
9func main() {
10 var b [0]byte;
Russ Coxe2bf2272009-04-16 23:07:15 -070011 s := string(&b); // out of bounds trap
Russ Cox5383e282008-09-22 20:12:15 -070012 if s != "" {
13 panic("bad convert")
14 }
Russ Coxbe2edb52009-03-03 08:39:12 -080015 var b1 = [5]byte{'h', 'e', 'l', 'l', 'o'};
Russ Coxe2bf2272009-04-16 23:07:15 -070016 if string(&b1) != "hello" {
Russ Cox5383e282008-09-22 20:12:15 -070017 panic("bad convert 1")
18 }
Russ Cox55645042009-01-06 15:19:02 -080019 var b2 = make([]byte, 5);
Russ Cox5383e282008-09-22 20:12:15 -070020 for i := 0; i < 5; i++ { b2[i] = b1[i] }
21 if string(b2) != "hello" {
22 panic("bad convert 2")
23 }
Russ Cox96b90642008-09-12 09:43:21 -070024}
25