Source file
test/fixedbugs/issue24187.go
1
2
3
4
5
6
7
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 }
35
View as plain text