blob: 960c81862df9b0b3456ca8326bb0096eaaf75c2b [file] [log] [blame]
Alexey Samsonov00cd2732014-01-21 11:58:33 +00001// RUN: %clang_asan -O2 %s -o %t
2// RUN: ASAN_OPTIONS=check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
3// RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
4// RUN: %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9int main() {
10 volatile char c = '0';
11 volatile int x = 12;
12 volatile float f = 1.239;
13 volatile char s[] = "34";
14 char *p = strdup((const char *)s);
15 free(p);
16 printf("%c %d %.3f %s\n", c, x, f, p);
17 return 0;
18 // Check that %s is sanitized.
19 // CHECK-ON: heap-use-after-free
20 // CHECK-ON-NOT: 0 12 1.239 34
21 // CHECK-OFF: 0 12 1.239
22}