Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_asan -O0 %s -o %t |
| 2 | // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=MALLOC-CTX |
| 3 | |
| 4 | // Also works if no malloc context is available. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 5 | // RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s |
| 6 | // RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 7 | // XFAIL: arm-linux-gnueabi |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 8 | // XFAIL: armv7l-unknown-linux-gnueabihf |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | int main(int argc, char **argv) { |
| 13 | char *x = (char*)malloc(10 * sizeof(char)); |
| 14 | memset(x, 0, 10); |
| 15 | int res = x[argc]; |
| 16 | free(x + 5); // BOOM |
| 17 | // CHECK: AddressSanitizer: attempting free on address{{.*}}in thread T0 |
| 18 | // CHECK: invalid-free.cc:[[@LINE-2]] |
| 19 | // CHECK: is located 5 bytes inside of 10-byte region |
| 20 | // CHECK: allocated by thread T0 here: |
| 21 | // MALLOC-CTX: invalid-free.cc:[[@LINE-8]] |
| 22 | return res; |
| 23 | } |