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=unix.StdCLibraryFunctions \
5 // RUN: -analyzer-config 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{{'errno' may be undefined after successful call to 'fopen'}}
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{{'errno' may be undefined after successful call to 'tmpfile'}}
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{{'errno' may be undefined after successful call to 'freopen'}}
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{{'errno' may be undefined after successful call to 'fclose'}}
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{{'errno' may be undefined after successful call to 'fread'}}
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_fread_size0(void) {
81 // expected-note@+2{{'F' is non-null}}
82 // expected-note@+1{{Taking false branch}}
86 // expected-note@-1{{'errno' may be undefined after successful call to 'fread'}}
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'}}
91 void check_fread_nmemb0(void) {
94 // expected-note@+2{{'F' is non-null}}
95 // expected-note@+1{{Taking false branch}}
99 // expected-note@-1{{'errno' may be undefined after successful call to 'fread'}}
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'}}
104 void check_fwrite(void) {
105 char Buf
[] = "0123456789";
107 // expected-note@+2{{'F' is non-null}}
108 // expected-note@+1{{Taking false branch}}
111 int R
= fwrite(Buf
, 1, 10, F
);
112 // expected-note@-1{{'errno' may be undefined after successful call to 'fwrite'}}
113 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
114 // expected-note@-1{{An undefined value may be read from 'errno'}}
118 void check_fseek(void) {
120 // expected-note@+2{{'F' is non-null}}
121 // expected-note@+1{{Taking false branch}}
124 (void)fseek(F
, 11, SEEK_SET
);
125 // expected-note@-1{{'errno' may be undefined after successful call to 'fseek'}}
126 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
127 // expected-note@-1{{An undefined value may be read from 'errno'}}
131 void check_rewind_errnocheck(void) {
133 // expected-note@+2{{'F' is non-null}}
134 // expected-note@+1{{Taking false branch}}
138 rewind(F
); // expected-note{{'rewind' indicates failure only by setting 'errno'}}
139 fclose(F
); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'fclose' [alpha.unix.Errno]}}
140 // expected-note@-1{{Value of 'errno' was not checked and may be overwritten by function 'fclose'}}
143 void check_fileno(void) {
145 // expected-note@+2{{'F' is non-null}}
146 // expected-note@+1{{Taking false branch}}
150 // expected-note@-1{{'errno' may be undefined after successful call to 'fileno'}}
151 if (errno
) {} // expected-warning{{An undefined value may be read from 'errno'}}
152 // expected-note@-1{{An undefined value may be read from 'errno'}}