6 /* Wanalyzer-out-of-bounds tests for buffer over-reads. */
8 /* Avoid folding of memcpy. */
9 typedef void * (*memcpy_t
) (void *dst
, const void *src
, size_t n
);
11 static memcpy_t
__attribute__((noinline
))
21 memset (id_sequence
, 0, 3 * sizeof(int));
22 printf ("%i", id_sequence
[3]); /* { dg-line test1 } */
24 /* { dg-warning "stack-based buffer over-read" "warning" { target *-*-* } test1 } */
25 /* { dg-message "read of 4 bytes from after the end of 'id_sequence'" "num bad bytes note" { target *-*-* } test1 } */
26 /* { dg-message "valid subscripts for 'id_sequence' are '\\\[0\\\]' to '\\\[2\\\]'" "valid subscript note" { target *-*-* } test1 } */
33 memset (arr
, 0, n
* sizeof (int));
36 for (int i
= n
- 1; i
>= 0; i
--)
44 memset (arr
, 0, n
* sizeof (int));
47 for (int i
= n
; i
> 0; i
--)
48 sum
+= arr
[i
]; /* { dg-line test3 } */
50 /* { dg-warning "stack-based buffer over-read" "warning" { target *-*-* } test3 } */
51 /* { dg-message "" "note" { target *-*-* } test3 } */
57 int *arr
= (int *)malloc (n
* sizeof (int));
60 memset (arr
, 0, n
* sizeof(int));
63 for (int i
= n
- 1; i
>= 0; i
--)
72 int *arr
= (int *)malloc (n
* sizeof (int));
75 memset (arr
, 0, n
* sizeof(int));
78 for (int i
= n
; i
> 0; i
--)
79 sum
+= *(arr
+ i
); /* { dg-line test5 } */
82 /* { dg-warning "heap-based buffer over-read" "bounds warning" { target *-*-* } test5 } */
83 /* { dg-message "read of 4 bytes from after the end of the region" "num bad bytes note" { target *-*-* } test5 } */