blob: e93c60ca9391bd34de3a290b4528c813993bf2ef [file] [log] [blame]
Alexey Samsonov00cd2732014-01-21 11:58:33 +00001// RUN: %clang_asan -O2 %s -o %t
Alexander Potapenko844a3cf2014-02-04 11:32:05 +00002// We need replace_str=0 and replace_intrin=0 to avoid reporting errors in
3// strlen() and memcpy() called by puts().
4// RUN: ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
5// RUN: ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
6// RUN: ASAN_OPTIONS=replace_str=0:replace_intrin=0 %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
Alexey Samsonov00cd2732014-01-21 11:58:33 +00007
8#include <stdio.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 volatile char buf[2];
15 sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s);
16 puts((const char *)buf);
17 return 0;
18 // Check that size of output buffer is sanitized.
19 // CHECK-ON: stack-buffer-overflow
20 // CHECK-ON-NOT: 0 12 1.239 34
21 // CHECK-OFF: 0 12 1.239 34
22}