1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
2 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
4 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection \
5 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s
7 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
8 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdfunc,any %s
10 #include "Inputs/system-header-simulator.h"
12 extern void clang_analyzer_eval(int);
18 void test_fopen(void) {
19 FILE *fp
= fopen("path", "r");
20 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}} any-warning{{FALSE}}
22 // stream-warning{{Stream pointer might be NULL}} \
23 // stdfunc-warning{{should not be NULL}}
26 void test_tmpfile(void) {
28 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}} any-warning{{FALSE}}
30 // stream-warning{{Stream pointer might be NULL}} \
31 // stdfunc-warning{{should not be NULL}}
34 void test_fclose(void) {
37 // stream-warning{{Stream pointer might be NULL}} \
38 // stdfunc-warning{{should not be NULL}}
39 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
42 void test_freopen(void) {
44 fp
= freopen("file", "w", fp
); // \
45 // stream-warning{{Stream pointer might be NULL}} \
46 // stdfunc-warning{{should not be NULL}}
48 // stream-warning{{Stream pointer might be NULL}} \
49 // stdfunc-warning{{should not be NULL}}
50 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
53 void test_fread(void) {
55 size_t ret
= fread(buf
, size
, n
, fp
); // \
56 // stream-warning{{Stream pointer might be NULL}} \
57 // stdfunc-warning{{The 4th argument to 'fread' is NULL but should not be NULL}}
58 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
59 clang_analyzer_eval(ret
<= n
); // any-warning{{TRUE}}
60 clang_analyzer_eval(ret
== n
); // any-warning{{TRUE}} any-warning{{FALSE}}
65 void test_fwrite(void) {
67 size_t ret
= fwrite(buf
, size
, n
, fp
); // \
68 // stream-warning{{Stream pointer might be NULL}} \
69 // stdfunc-warning{{The 4th argument to 'fwrite' is NULL but should not be NULL}}
70 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
71 clang_analyzer_eval(ret
<= n
); // any-warning{{TRUE}}
72 clang_analyzer_eval(ret
== n
); // any-warning{{TRUE}} any-warning{{FALSE}}
77 void test_fseek(void) {
80 // stream-warning{{Stream pointer might be NULL}} \
81 // stdfunc-warning{{should not be NULL}}
82 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
86 void test_ftell(void) {
89 // stream-warning{{Stream pointer might be NULL}} \
90 // stdfunc-warning{{should not be NULL}}
91 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
95 void test_rewind(void) {
98 // stream-warning{{Stream pointer might be NULL}} \
99 // stdfunc-warning{{should not be NULL}}
100 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
104 void test_fgetpos(void) {
105 FILE *fp
= tmpfile();
107 fgetpos(fp
, &pos
); // \
108 // stream-warning{{Stream pointer might be NULL}} \
109 // stdfunc-warning{{should not be NULL}}
110 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
114 void test_fsetpos(void) {
115 FILE *fp
= tmpfile();
117 fsetpos(fp
, &pos
); // \
118 // stream-warning{{Stream pointer might be NULL}} \
119 // stdfunc-warning{{should not be NULL}}
120 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
124 void test_clearerr(void) {
125 FILE *fp
= tmpfile();
127 // stream-warning{{Stream pointer might be NULL}} \
128 // stdfunc-warning{{should not be NULL}}
129 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
133 void test_feof(void) {
134 FILE *fp
= tmpfile();
136 // stream-warning{{Stream pointer might be NULL}} \
137 // stdfunc-warning{{should not be NULL}}
138 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
142 void test_ferror(void) {
143 FILE *fp
= tmpfile();
145 // stream-warning{{Stream pointer might be NULL}} \
146 // stdfunc-warning{{should not be NULL}}
147 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}
151 void test_fileno(void) {
152 FILE *fp
= tmpfile();
154 // stream-warning{{Stream pointer might be NULL}} \
155 // stdfunc-warning{{should not be NULL}}
156 clang_analyzer_eval(fp
!= NULL
); // any-warning{{TRUE}}