1 | // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t |
2 | // RUN: %clangxx_msan -std=c++11 -fsanitize-memory-track-origins -O0 %s -o %t && %run %t |
3 | |
4 | #include <assert.h> |
5 | #include <stdio.h> |
6 | |
7 | #include <sanitizer/msan_interface.h> |
8 | |
9 | int main(int argc, char *argv[]) { |
10 | FILE *f = fopen(filename: argv[0], modes: "r" ); |
11 | assert(f); |
12 | char buf[50]; |
13 | fread(ptr: buf, size: 1, n: 1, stream: f); |
14 | fflush(stream: f); |
15 | |
16 | assert(f->_IO_read_end > f->_IO_read_base); |
17 | __msan_check_mem_is_initialized(x: f->_IO_read_end, size: f->_IO_read_end - f->_IO_read_base); |
18 | |
19 | char tmp_file[1000]; |
20 | sprintf(s: tmp_file, format: "%s.write.tmp" , argv[0]); |
21 | |
22 | f = fopen(filename: tmp_file, modes: "w+" ); |
23 | assert(f); |
24 | fwrite(ptr: buf, size: 1, n: 1, s: f); |
25 | fflush(stream: f); |
26 | |
27 | assert(f->_IO_write_end > f->_IO_write_base); |
28 | __msan_check_mem_is_initialized(x: f->_IO_write_end, size: f->_IO_write_end - f->_IO_write_base); |
29 | } |
30 | |