Debian Codegraph @

src/cmd/cgo/internal/testsanitizers/testdata/msan_fail.go

raw
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
5 package main
6
7 /*
8 #include <string.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11
12 void f(int32_t *p, int n) {
13 int32_t * volatile q = (int32_t *)malloc(sizeof(int32_t) * n);
14 memcpy(p, q, n * sizeof(*p));
15 free(q);
16 }
17
18 void g(int32_t *p, int n) {
19 if (p[4] != 1) {
20 // We shouldn't get here; msan should stop us first.
21 exit(0);
22 }
23 }
24 */
25 import "C"
26
27 import (
28 "unsafe"
29 )
30
31 func main() {
32 a := make([]int32, 10)
33 C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
34 a[3] = 1
35 C.g((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
36 }