Skip to content

Commit 311cf4e

Browse files
committed
C++: add false positives to MissingCheckScanf test
See github#12412 for the initial report.
1 parent 0f4df0d commit 311cf4e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@
1919
| test.cpp:302:8:302:12 | ptr_i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:301:3:301:7 | call to scanf | call to scanf |
2020
| test.cpp:310:7:310:7 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:309:3:309:7 | call to scanf | call to scanf |
2121
| test.cpp:404:25:404:25 | u | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:403:6:403:11 | call to sscanf | call to sscanf |
22+
| test.cpp:416:7:416:7 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:413:7:413:11 | call to scanf | call to scanf |
23+
| test.cpp:423:7:423:7 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:420:7:420:11 | call to scanf | call to scanf |

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,20 @@ char *my_string_copy() {
406406
*ptr++ = 0;
407407
return DST_STRING;
408408
}
409+
410+
void scan_and_write() {
411+
{
412+
int i;
413+
if (scanf("%d", &i) < 1) {
414+
i = 0;
415+
}
416+
use(i); // GOOD [FALSE POSITIVE]: variable is overwritten with a default value when scanf fails
417+
}
418+
{
419+
int i;
420+
if (scanf("%d", &i) != 1) {
421+
i = 0;
422+
}
423+
use(i); // GOOD [FALSE POSITIVE]: variable is overwritten with a default value when scanf fails
424+
}
425+
}

0 commit comments

Comments
 (0)