Skip to content

Commit ce8d05a

Browse files
committed
Add more (false-negative) MissingCheckScanf tests
1 parent c62ae3b commit ce8d05a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

cpp/ql/test/query-tests/Critical/MissingCheckScanf/MissingCheckScanf.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
| test.cpp:39:3:39:7 | call to scanf | This is a call to scanf. |
33
| test.cpp:48:3:48:8 | call to fscanf | This is a call to scanf. |
44
| 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. |

cpp/ql/test/query-tests/Critical/MissingCheckScanf/test.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,43 @@ int main()
9494
}
9595
}
9696

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+
97109
{
98110
bool b;
99111
int i;
100112

101-
b = scanf("%d", &i); // GOOD
113+
b = scanf("%d", &i); // BAD [NOT DETECTED]: scanf can return EOF (boolifies true)
102114

103115
if (b >= 1)
104116
{
105117
use(i);
106118
}
107119
}
108120

121+
{
122+
bool b;
123+
int i;
124+
125+
b = scanf("%d", &i); // BAD [NOT DETECTED]
126+
127+
use(i);
128+
}
129+
109130
{
110131
int i, j;
111132

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
113134
{
114135
use(i);
115136
use(j);
@@ -165,7 +186,7 @@ int main()
165186
}
166187

167188
// --- different use ---
168-
189+
169190
{
170191
int i;
171192
int *ptr_i = &i;

0 commit comments

Comments
 (0)