1 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
2 // RUN: -analyzer-checker=alpha.unix.Stream \
3 // RUN: -analyzer-checker=alpha.unix.Errno \
4 // RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctions \
5 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true \
6 // RUN: -analyzer-output text -verify %s
8 #include "Inputs/system-header-simulator.h"
9 #include "Inputs/errno_func.h"
11 void check_fopen(void) {
12 FILE *F
= fopen("xxx", "r");
13 // expected-note@-1{{Assuming that function 'fopen' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
14 // expected-note@+2{{'F' is non-null}}
15 // expected-note@+1{{Taking false branch}}
18 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
19 // expected-note@-1{{An undefined value may be read from 'errno'}}
23 void check_tmpfile(void) {
25 // expected-note@-1{{Assuming that function 'tmpfile' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
26 // expected-note@+2{{'F' is non-null}}
27 // expected-note@+1{{Taking false branch}}
30 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno' [alpha.unix.Errno]}}
31 // expected-note@-1{{An undefined value may be read from 'errno'}}
35 void check_freopen(void) {
37 // expected-note@+2{{'F' is non-null}}
38 // expected-note@+1{{Taking false branch}}
41 F
= freopen("xxx", "w", F
);
42 // expected-note@-1{{Assuming that function 'freopen' is successful}}
43 // expected-note@+2{{'F' is non-null}}
44 // expected-note@+1{{Taking false branch}}
47 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
48 // expected-note@-1{{An undefined value may be read from 'errno'}}
52 void check_fclose(void) {
54 // expected-note@+2{{'F' is non-null}}
55 // expected-note@+1{{Taking false branch}}
59 // expected-note@-1{{Assuming that function 'fclose' is successful}}
60 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
61 // expected-note@-1{{An undefined value may be read from 'errno'}}
64 void check_fread(void) {
67 // expected-note@+2{{'F' is non-null}}
68 // expected-note@+1{{Taking false branch}}
71 (void)fread(Buf
, 1, 10, F
);
72 // expected-note@-1{{Assuming that function 'fread' is successful}}
73 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
74 // expected-note@-1{{An undefined value may be read from 'errno'}}
78 void check_fwrite(void) {
79 char Buf
[] = "0123456789";
81 // expected-note@+2{{'F' is non-null}}
82 // expected-note@+1{{Taking false branch}}
85 int R
= fwrite(Buf
, 1, 10, F
);
86 // expected-note@-1{{Assuming that function 'fwrite' is successful}}
87 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
88 // expected-note@-1{{An undefined value may be read from 'errno'}}
92 void check_fseek(void) {
94 // expected-note@+2{{'F' is non-null}}
95 // expected-note@+1{{Taking false branch}}
98 (void)fseek(F
, 11, SEEK_SET
);
99 // expected-note@-1{{Assuming that function 'fseek' is successful}}
100 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
101 // expected-note@-1{{An undefined value may be read from 'errno'}}
105 void check_rewind_errnocheck(void) {
107 // expected-note@+2{{'F' is non-null}}
108 // expected-note@+1{{Taking false branch}}
112 rewind(F
); // expected-note{{Function 'rewind' indicates failure only by setting of 'errno'}}
113 fclose(F
); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'fclose' [alpha.unix.Errno]}}
114 // expected-note@-1{{Value of 'errno' was not checked and may be overwritten by function 'fclose'}}
117 void check_fileno(void) {
119 // expected-note@+2{{'F' is non-null}}
120 // expected-note@+1{{Taking false branch}}
124 // expected-note@-1{{Assuming that function 'fileno' is successful}}
125 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
126 // expected-note@-1{{An undefined value may be read from 'errno'}}