blob: 4f54ff956e3d0ce3755f8bf5a27e541373f6ea57 [file] [log] [blame]
Alexey Samsonov00cd2732014-01-21 11:58:33 +00001// RUN: %clang_asan -O2 %s -o %t
Reid Kleckner85220d02015-08-12 23:50:12 +00002// RUN: %env_asan_opts=check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
3// RUN: %env_asan_opts=check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
Greg Fitzgeraldb8aae542014-04-30 21:34:17 +00004// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
Alexey Samsonov00cd2732014-01-21 11:58:33 +00005
Timur Iskhodzhanov7f291812014-05-28 13:06:14 +00006// FIXME: printf is not intercepted on Windows yet.
Petr Hosekeb46c952018-08-09 02:16:18 +00007// XFAIL: windows-msvc
Timur Iskhodzhanov7f291812014-05-28 13:06:14 +00008
Vitaly Bukaa938b9d2018-12-20 00:24:09 +00009// New Bionic rejects %n
10// https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336
11// UNSUPPORTED: android
12
Alexey Samsonov00cd2732014-01-21 11:58:33 +000013#include <stdio.h>
14int main() {
Reid Kleckner89d99432015-08-14 17:39:48 +000015#ifdef _MSC_VER
16 // FIXME: The test raises a dialog even though it's XFAILd.
17 return 42;
18#endif
Alexey Samsonov00cd2732014-01-21 11:58:33 +000019 volatile char c = '0';
20 volatile int x = 12;
21 volatile float f = 1.239;
22 volatile char s[] = "34";
23 volatile int n[1];
24 printf("%c %d %.3f %s%n\n", c, x, f, s, &n[1]);
25 return 0;
26 // Check that %n is sanitized.
27 // CHECK-ON: stack-buffer-overflow
28 // CHECK-ON-NOT: 0 12 1.239 34
29 // CHECK-OFF: 0 12 1.239 34
30}