2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / c-c++-common / asan / heap-overflow-1.c
blob996909d3c8e3d8888a4a283ea05124eee55b838c
1 /* { dg-do run } */
2 /* { dg-options "-fno-builtin-malloc -fno-builtin-free -fno-builtin-memset" } */
3 /* { dg-shouldfail "asan" } */
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
9 void *memset (void *, int, __SIZE_TYPE__);
10 void *malloc (__SIZE_TYPE__);
11 void free (void *);
13 #ifdef __cplusplus
15 #endif
17 volatile int ten = 10;
18 int main(int argc, char **argv) {
19 char *x = (char*)malloc(10);
20 memset(x, 0, 10);
21 int res = x[ten]; /* BOOOM */
22 free(x);
23 return res;
26 /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
27 /* { dg-output " #0 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*heap-overflow-1.c:21|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
28 /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes to the right of 10-byte region\[^\n\r]*(\n|\r\n|\r)" } */
29 /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
30 /* { dg-output " #0 0x\[0-9a-f\]+ (in _*(interceptor_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
31 /* { dg-output " #1 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*heap-overflow-1.c:19|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */