Source file src/cmd/cgo/internal/testsanitizers/testdata/asan_global3_fail.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  /*
     8  #include <stdlib.h>
     9  #include <stdio.h>
    10  
    11  int test(int *a) {
    12  	int* p = a+1;
    13  	*p = 10;          // BOOM
    14  	return *p;
    15  }
    16  */
    17  import "C"
    18  import (
    19  	"fmt"
    20  	"unsafe"
    21  )
    22  
    23  var cIntV C.int
    24  
    25  func main() {
    26  	r := C.test((*C.int)(unsafe.Pointer(&cIntV)))
    27  	fmt.Printf("r value is %d", r)
    28  }
    29  

View as plain text