Source file src/cmd/cgo/internal/testsanitizers/testdata/asan4_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  	a[3] = 300;          // BOOM
    14  	// We shouldn't get here; asan should stop us first.
    15  	printf("a[3]=%d\n", a[3]);
    16  }*/
    17  import "C"
    18  
    19  func main() {
    20  	var cIntArray [2]C.int
    21  	C.test(&cIntArray[0]) // cIntArray is moved to heap.
    22  }
    23  

View as plain text