summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/bounds-9.c
blob: 61c11f4b3b8a2f9439bbfab260b6ead5058f91e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* PR sanitizer/65280 */
/* { dg-do run } */
/* { dg-options "-fsanitize=bounds" } */
/* Origin: Martin Uecker <uecker@eecs.berkeley.edu> */

void
foo (volatile int (*a)[3])
{
  (*a)[3] = 1;	// error
  a[0][0] = 1;	// ok
  a[1][0] = 1;	// ok
  a[1][4] = 1;	// error
}

int
main ()
{
  volatile int a[20];
  foo ((int (*)[3]) &a);
  return 0;
}

/* { dg-output "index 3 out of bounds for type 'int \\\[3\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 4 out of bounds for type 'int \\\[3\\\]'" } */