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

     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 <stdint.h>
     9  
    10  void f(int32_t *p, int n) {
    11    int i;
    12  
    13    for (i = 0; i < n; i++) {
    14      p[i] = (int32_t)i;
    15    }
    16  }
    17  */
    18  import "C"
    19  
    20  import (
    21  	"fmt"
    22  	"os"
    23  	"unsafe"
    24  )
    25  
    26  func main() {
    27  	a := make([]int32, 10)
    28  	C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
    29  	for i, v := range a {
    30  		if i != int(v) {
    31  			fmt.Printf("bad %d: %v\n", i, a)
    32  			os.Exit(1)
    33  		}
    34  	}
    35  }
    36  

View as plain text