Debian Codegraph @

test/fixedbugs/issue24187.go

raw
1 // run
2
3 //go:build amd64p32
4
5 // Copyright 2018 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
8
9 package main
10
11 import (
12 "bytes"
13 "fmt"
14 "unsafe"
15 )
16
17 func main() {
18 b := make([]byte, 128)
19 for i := range b {
20 b[i] = 1
21 }
22 if bytes.IndexByte(b, 0) != -1 {
23 panic("found 0")
24 }
25 for i := range b {
26 b[i] = 0
27 c := b
28 *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&c)) + unsafe.Sizeof(uintptr(0)))) = 1<<31 - 1
29 if bytes.IndexByte(c, 0) != i {
30 panic(fmt.Sprintf("missing 0 at %d\n", i))
31 }
32 b[i] = 1
33 }
34 }