File tree 2 files changed +29
-8
lines changed
cpp/ql/test/query-tests/Critical/MissingCheckScanf 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change 2
2
| test.cpp:39:3:39:7 | call to scanf | This is a call to scanf. |
3
3
| test.cpp:48:3:48:8 | call to fscanf | This is a call to scanf. |
4
4
| test.cpp:55:3:55:8 | call to sscanf | This is a call to scanf. |
5
- | test.cpp:135 :3:135 :7 | call to scanf | This is a call to scanf. |
6
- | test.cpp:143 :3:143 :7 | call to scanf | This is a call to scanf. |
7
- | test.cpp:151 :3:151 :7 | call to scanf | This is a call to scanf. |
8
- | test.cpp:163 :3:163 :7 | call to scanf | This is a call to scanf. |
9
- | test.cpp:173 :3:173 :7 | call to scanf | This is a call to scanf. |
5
+ | test.cpp:156 :3:156 :7 | call to scanf | This is a call to scanf. |
6
+ | test.cpp:164 :3:164 :7 | call to scanf | This is a call to scanf. |
7
+ | test.cpp:172 :3:172 :7 | call to scanf | This is a call to scanf. |
8
+ | test.cpp:184 :3:184 :7 | call to scanf | This is a call to scanf. |
9
+ | test.cpp:194 :3:194 :7 | call to scanf | This is a call to scanf. |
Original file line number Diff line number Diff line change @@ -94,22 +94,43 @@ int main()
94
94
}
95
95
}
96
96
97
+ {
98
+ int r;
99
+ int i;
100
+
101
+ r = scanf (" %d" , &i); // GOOD
102
+
103
+ if (r >= 1 )
104
+ {
105
+ use (i);
106
+ }
107
+ }
108
+
97
109
{
98
110
bool b;
99
111
int i;
100
112
101
- b = scanf (" %d" , &i); // GOOD
113
+ b = scanf (" %d" , &i); // BAD [NOT DETECTED]: scanf can return EOF (boolifies true)
102
114
103
115
if (b >= 1 )
104
116
{
105
117
use (i);
106
118
}
107
119
}
108
120
121
+ {
122
+ bool b;
123
+ int i;
124
+
125
+ b = scanf (" %d" , &i); // BAD [NOT DETECTED]
126
+
127
+ use (i);
128
+ }
129
+
109
130
{
110
131
int i, j;
111
132
112
- if (scanf (" %d %d" , &i) >= 2 ) // GOOD
133
+ if (scanf (" %d %d" , &i) >= 2 ) // GOOD: `j` is not a scanf arg, so out of scope of MissingCheckScanf
113
134
{
114
135
use (i);
115
136
use (j);
@@ -165,7 +186,7 @@ int main()
165
186
}
166
187
167
188
// --- different use ---
168
-
189
+
169
190
{
170
191
int i;
171
192
int *ptr_i = &i;
You can’t perform that action at this time.
0 commit comments