Source file
test/fixedbugs/issue8606b.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package main
21
22 import (
23 "fmt"
24 "reflect"
25 "syscall"
26 "unsafe"
27 )
28
29 type SI struct {
30 s string
31 i int
32 }
33
34 type SS struct {
35 s string
36 t string
37 }
38
39 func main() {
40 bad1 := "foo"
41 bad2 := "foo"
42
43 p := syscall.Getpagesize()
44 b, err := syscall.Mmap(-1, 0, p, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
45 if err != nil {
46 panic(err)
47 }
48 err = syscall.Mprotect(b, syscall.PROT_NONE)
49 if err != nil {
50 panic(err)
51 }
52
53 (*reflect.StringHeader)(unsafe.Pointer(&bad1)).Data = uintptr(unsafe.Pointer(&b[0]))
54 (*reflect.StringHeader)(unsafe.Pointer(&bad2)).Data = uintptr(unsafe.Pointer(&b[1]))
55
56 for _, test := range []struct {
57 a, b interface{}
58 }{
59 {SI{s: bad1, i: 1}, SI{s: bad2, i: 2}},
60 {SS{s: bad1, t: "a"}, SS{s: bad2, t: "aa"}},
61 {SS{s: "a", t: bad1}, SS{s: "b", t: bad2}},
62
63
64
65 } {
66 if test.a == test.b {
67 panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b))
68 }
69 }
70
71 }
72
View as plain text