...

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

Documentation: cmd/cgo/internal/testsanitizers/testdata

     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  var intGlo int
    13  
    14  func main() {
    15  	r := bar(&intGlo)
    16  	fmt.Printf("r value is %d", r)
    17  }
    18  
    19  func bar(a *int) int {
    20  	p := (*int)(unsafe.Add(unsafe.Pointer(a), 1*unsafe.Sizeof(int(1))))
    21  	if *p == 10 { // BOOM
    22  		fmt.Println("its value is 10")
    23  	}
    24  	return *p
    25  }
    26  

View as plain text