1// Copyright 2021 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 5package main 6 7/* 8#include <stdlib.h> 9#include <stdio.h> 10 11int *p; 12int* f() { 13 int i; 14 p = (int *)malloc(5*sizeof(int)); 15 for (i = 0; i < 5; i++) { 16 p[i] = i+10; 17 } 18 return p; 19} 20*/ 21import "C" 22import ( 23 "fmt" 24 "unsafe" 25) 26 27func main() { 28 a := C.f() 29 q5 := (*C.int)(unsafe.Add(unsafe.Pointer(a), 4*5)) 30 // Access to C pointer out of bounds. 31 *q5 = 100 // BOOM 32 // We shouldn't get here; asan should stop us first. 33 fmt.Printf("q5: %d, %x\n", *q5, q5) 34} 35