asan4_fail.go 496 B

12345678910111213141516171819202122
  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. package main
  5. /*
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. void test(int* a) {
  9. // Access Go pointer out of bounds.
  10. a[3] = 300; // BOOM
  11. // We shouldn't get here; asan should stop us first.
  12. printf("a[3]=%d\n", a[3]);
  13. }*/
  14. import "C"
  15. func main() {
  16. var cIntArray [2]C.int
  17. C.test(&cIntArray[0]) // cIntArray is moved to heap.
  18. }