Skip to content

Commit 94ff2e5

Browse files
committed
CPP: Lets just not report when we're not sure.
1 parent 2841897 commit 94ff2e5

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ private predicate formattingFunctionCallExpectedType(FormattingFunctionCall ffc,
2525
ffc.getTarget() = f and
2626
f.getFormatParameterIndex() = i and
2727
ffc.getArgument(i) = fl and
28-
fl.getConversionType(pos) = expected
28+
fl.getConversionType(pos) = expected and
29+
count(fl.getConversionType(pos)) = 1
2930
)
3031
}
3132

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_mixed_byte_wprintf/WrongTypeFormatArguments.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
| tests.cpp:18:15:18:22 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' |
22
| tests.cpp:19:15:19:22 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' |
3-
| tests.cpp:21:15:21:21 | Hello | This argument should be of type 'char16_t *' but is of type 'char *' |
4-
| tests.cpp:21:15:21:21 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' |
5-
| tests.cpp:22:15:22:22 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' |
6-
| tests.cpp:23:15:23:22 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *' |
73
| tests.cpp:25:17:25:23 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' |
84
| tests.cpp:26:17:26:24 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' |
95
| tests.cpp:30:17:30:24 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_mixed_byte_wprintf/tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ void tests() {
1818
printf("%s", u"Hello"); // BAD: expecting char
1919
printf("%s", L"Hello"); // BAD: expecting char
2020

21-
printf("%S", "Hello"); // BAD: expecting wchar_t or char16_t
22-
printf("%S", u"Hello"); // GOOD [FALSE POSITIVE]
23-
printf("%S", L"Hello"); // GOOD [FALSE POSITIVE]
21+
printf("%S", "Hello"); // BAD: expecting wchar_t or char16_t [NOT DETECTED]
22+
printf("%S", u"Hello"); // GOOD
23+
printf("%S", L"Hello"); // GOOD
2424

2525
wprintf(L"%s", "Hello"); // BAD: expecting wchar_t
2626
wprintf(L"%s", u"Hello"); // BAD: expecting wchar_t
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
| tests_32.cpp:14:16:14:23 | void_ptr | This argument should be of type 'long' but is of type 'void *' |
2-
| tests_32.cpp:15:15:15:15 | l | This argument should be of type 'void *' but is of type 'long' |
32
| tests_64.cpp:14:16:14:23 | void_ptr | This argument should be of type 'long' but is of type 'void *' |
4-
| tests_64.cpp:15:15:15:15 | l | This argument should be of type 'void *' but is of type 'long' |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_mixed_word_size/tests_32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ void test_32()
1212

1313
printf("%li", l); // GOOD
1414
printf("%li", void_ptr); // BAD
15-
printf("%p", l); // BAD
15+
printf("%p", l); // BAD [NOT DETECTED]
1616
printf("%p", void_ptr); // GOOD
1717
}

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_mixed_word_size/tests_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ void test_64()
1212

1313
printf("%li", l); // GOOD
1414
printf("%li", void_ptr); // BAD
15-
printf("%p", l); // BAD
15+
printf("%p", l); // BAD [NOT DETECTED]
1616
printf("%p", void_ptr); // GOOD
1717
}

0 commit comments

Comments
 (0)