• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
test_fread()8 int test_fread() {
9   FILE *f = fopen("/dev/zero", "r");
10   char c;
11   unsigned read = fread(&c, sizeof(c), 1, f);
12   fclose(f);
13   if (c == '1') // No error
14     return 1;
15   return 0;
16 }
17 
test_fwrite()18 int test_fwrite() {
19   FILE *f = fopen("/dev/null", "w");
20   char c;
21   if (fwrite(&c, sizeof(c), 1, f) != sizeof(c)) // BOOM
22     return 1;
23   return fclose(f);
24 }
25 
main(int argc,char * argv[])26 int 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 __interceptor_fwrite at offset 0 inside
35