Skip to content

Commit a57f803

Browse files
committed
C++: Address false positive results.
1 parent 1130870 commit a57f803

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ where
168168
formatOtherArgType(ffc, n, expected, arg, actual) and
169169
not actual.getUnspecifiedType().(IntegralType).getSize() = sizeof_IntType()
170170
) and
171+
// Exclude some cases where we're less confident the result is correct / clear / valuable
171172
not arg.isAffectedByMacro() and
172173
not arg.isFromUninstantiatedTemplate(_) and
173174
not actual.stripType() instanceof ErroneousType and
175+
not arg.getType().stripType().(RoutineType).getReturnType() instanceof ErroneousType and
174176
not arg.(Call).mayBeFromImplicitlyDeclaredFunction() and
175177
// Make sure that the format function definition is consistent
176178
count(ffc.getTarget().getFormatParameterIndex()) = 1
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
| second.cpp:13:19:13:19 | s | This format specifier for type 'size_t' does not match the argument type '..(*)(..)'. |
2-
| second.cpp:14:19:14:19 | s | This format specifier for type 'size_t' does not match the argument type '..(*)(..)'. |
3-
| second.cpp:15:18:15:18 | s | This format specifier for type 'int' does not match the argument type '..(*)(..)'. |
4-
| second.cpp:16:19:16:19 | s | This format specifier for type 'long' does not match the argument type '..(*)(..)'. |
5-
| second.cpp:17:20:17:20 | s | This format specifier for type 'long long' does not match the argument type '..(*)(..)'. |
6-
| second.cpp:18:18:18:18 | s | This format specifier for type 'unsigned int' does not match the argument type '..(*)(..)'. |
71
| second.cpp:26:18:26:39 | ... - ... | This format specifier for type 'int' does not match the argument type 'long'. |
82
| second.cpp:29:18:29:39 | ... - ... | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
93
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ void test_size_t() {
1010

1111
printf("%zd", s); // GOOD
1212
printf("%zi", s); // GOOD
13-
printf("%zu", s); // GOOD (we generally permit signedness changes) [FALSE POSITIVE]
14-
printf("%zx", s); // GOOD (we generally permit signedness changes) [FALSE POSITIVE]
15-
printf("%d", s); // BAD
16-
printf("%ld", s); // BAD
17-
printf("%lld", s); // BAD
18-
printf("%u", s); // BAD
13+
printf("%zu", s); // GOOD (we generally permit signedness changes)
14+
printf("%zx", s); // GOOD (we generally permit signedness changes)
15+
printf("%d", s); // BAD [NOT DETECTED]
16+
printf("%ld", s); // BAD [NOT DETECTED]
17+
printf("%lld", s); // BAD [NOT DETECTED]
18+
printf("%u", s); // BAD [NOT DETECTED]
1919

2020
char buffer[1024];
2121

0 commit comments

Comments
 (0)