1// RUN: %clangxx_msan -g %s -o %t
2// RUN: not %run %t 2>&1 | FileCheck %s
3// RUN: %t 1
4
5#include <stdio.h>
6#include <stdlib.h>
7
8int test_fread() {
9 FILE *f = fopen(filename: "/dev/zero", modes: "r");
10 char c;
11 unsigned read = fread(ptr: &c, size: sizeof(c), n: 1, stream: f);
12 fclose(stream: f);
13 if (c == '1') // No error
14 return 1;
15 return 0;
16}
17
18int test_fwrite() {
19 FILE *f = fopen(filename: "/dev/null", modes: "w");
20 char c;
21 if (fwrite(ptr: &c, size: sizeof(c), n: 1, s: f) != sizeof(c)) // BOOM
22 return 1;
23 return fclose(stream: f);
24}
25
26int main(int argc, char *argv[]) {
27 if (argc > 1)
28 test_fread();
29 else
30 test_fwrite();
31 return 0;
32}
33
34// CHECK: Uninitialized bytes in fwrite at offset 0 inside
35

source code of compiler-rt/test/msan/fread_fwrite.cpp