Source file src/cmd/cgo/internal/testsanitizers/testdata/asan_unsafe_fail3.go

     1  // Copyright 2022 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.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"unsafe"
    10  )
    11  
    12  func main() {
    13  	a := 1
    14  	b := 2
    15  	// The local variables.
    16  	// When -asan is enabled, the unsafe.Pointer(&a) conversion is escaping.
    17  	var p *int = (*int)(unsafe.Add(unsafe.Pointer(&a), 1*unsafe.Sizeof(int(1))))
    18  	*p = 20 // BOOM
    19  	d := a + b
    20  	fmt.Println(d)
    21  }
    22  

View as plain text