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

     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  
     5  package main
     6  
     7  /*
     8  #include <stdlib.h>
     9  #include <stdio.h>
    10  
    11  void test(int *a) {
    12  	// Access Go pointer out of bounds.
    13  	int c = a[5];        // BOOM
    14  	// We shouldn't get here; asan should stop us first.
    15  	printf("a[5]=%d\n", c);
    16  }
    17  */
    18  import "C"
    19  
    20  func main() {
    21  	cIntSlice := []C.int{200, 201, 203, 203, 204}
    22  	C.test(&cIntSlice[0])
    23  }
    24  

View as plain text