• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 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#cgo LDFLAGS: -fsanitize=memory
9#cgo CPPFLAGS: -fsanitize=memory
10
11#include <string.h>
12#include <stdint.h>
13#include <stdlib.h>
14
15void f(int32_t *p, int n) {
16  int32_t * volatile q = (int32_t *)malloc(sizeof(int32_t) * n);
17  memcpy(p, q, n * sizeof(*p));
18  free(q);
19}
20
21void g(int32_t *p, int n) {
22  if (p[4] != 1) {
23    abort();
24  }
25}
26*/
27import "C"
28
29import (
30	"unsafe"
31)
32
33func main() {
34	a := make([]int32, 10)
35	C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
36	a[4] = 1
37	C.g((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
38}
39