asan3_fail.go 486 B

1234567891011121314151617181920212223
  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. int c = a[5]; // BOOM
  11. // We shouldn't get here; asan should stop us first.
  12. printf("a[5]=%d\n", c);
  13. }
  14. */
  15. import "C"
  16. func main() {
  17. cIntSlice := []C.int{200, 201, 203, 203, 204}
  18. C.test(&cIntSlice[0])
  19. }