1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 x = unsafe.Pointer(y) // want "possible misuse of unsafe.Pointer"
18 // only allowed pointer arithmetic is ptr +/-/&^ num.
19 // num+ptr is technically okay but still flagged: write ptr+num instead.
20 x = unsafe.Pointer(uintptr(x) + 1)
21 x = unsafe.Pointer(((uintptr((x))) + 1))
22 x = unsafe.Pointer(1 + uintptr(x)) // want "possible misuse of unsafe.Pointer"
23 x = unsafe.Pointer(uintptr(x) + uintptr(x)) // want "possible misuse of unsafe.Pointer"
24 x = unsafe.Pointer(uintptr(x) - 1)
25 x = unsafe.Pointer(1 - uintptr(x)) // want "possible misuse of unsafe.Pointer"
26 x = unsafe.Pointer(uintptr(x) &^ 3)
27 x = unsafe.Pointer(1 &^ uintptr(x)) // want "possible misuse of unsafe.Pointer"
29 // certain uses of reflect are okay
31 x = unsafe.Pointer(v.Pointer())
32 x = unsafe.Pointer(v.Pointer() + 1) // want "possible misuse of unsafe.Pointer"
33 x = unsafe.Pointer(v.UnsafeAddr())
34 x = unsafe.Pointer((v.UnsafeAddr()))
35 var s1 *reflect.StringHeader
36 x = unsafe.Pointer(s1.Data)
37 x = unsafe.Pointer(s1.Data + 1) // want "possible misuse of unsafe.Pointer"
38 var s2 *reflect.SliceHeader
39 x = unsafe.Pointer(s2.Data)
40 var s3 reflect.StringHeader
41 x = unsafe.Pointer(s3.Data) // want "possible misuse of unsafe.Pointer"
42 var s4 reflect.SliceHeader
43 x = unsafe.Pointer(s4.Data) // want "possible misuse of unsafe.Pointer"
45 // but only in reflect
47 x = unsafe.Pointer(vv.Pointer()) // want "possible misuse of unsafe.Pointer"
48 x = unsafe.Pointer(vv.UnsafeAddr()) // want "possible misuse of unsafe.Pointer"
50 x = unsafe.Pointer(ss1.Data) // want "possible misuse of unsafe.Pointer"
52 x = unsafe.Pointer(ss2.Data) // want "possible misuse of unsafe.Pointer"
61 type StringHeader struct {
65 type SliceHeader struct {