Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c98eda5

Browse filesBrowse files
committed
C++: Remove potential FPs in cpp/wrong-type-format-argument in BMN
1 parent 231e3c2 commit c98eda5
Copy full SHA for c98eda5

File tree

3 files changed

+9
-6
lines changed
Filter options

3 files changed

+9
-6
lines changed

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

Copy file name to clipboardExpand all lines: cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ predicate trivialConversion(ExpectedType expected, Type actual) {
152152
*/
153153
int sizeof_IntType() { exists(IntType it | result = it.getSize()) }
154154

155+
predicate buildModeNoneIntLongConversion(IntType formatType, LongType argumentType) {
156+
exists(formatType) and
157+
exists(argumentType) and
158+
exists(Compilation c | c.buildModeNone())
159+
}
160+
155161
from FormattingFunctionCall ffc, int n, Expr arg, Type expected, Type actual
156162
where
157163
(
@@ -171,7 +177,8 @@ where
171177
not arg.isAffectedByMacro() and
172178
not arg.isFromUninstantiatedTemplate(_) and
173179
not actual.stripType() instanceof ErroneousType and
174-
not arg.(Call).mayBeFromImplicitlyDeclaredFunction()
180+
not arg.(Call).mayBeFromImplicitlyDeclaredFunction() and
181+
not buildModeNoneIntLongConversion(expected, actual.getUnspecifiedType())
175182
select arg,
176183
"This format specifier for type '" + expected.getName() + "' does not match the argument type '" +
177184
actual.getUnspecifiedType().getName() + "'."

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

Copy file name to clipboardExpand all lines: cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/WrongTypeFormatArguments.expected
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |
2-
| tests.c:12:27:12:29 | 42 | This format specifier for type 'int' does not match the argument type 'long'. |
3-
| tests.c:12:32:12:35 | 42 | This format specifier for type 'int' does not match the argument type 'unsigned long'. |
4-
| tests.c:12:38:12:40 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
5-
| tests.c:12:43:12:46 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'unsigned long'. |
62
| tests.c:13:27:13:30 | 42 | This format specifier for type 'int' does not match the argument type 'long long'. |
73
| tests.c:13:33:13:37 | 42 | This format specifier for type 'int' does not match the argument type 'unsigned long long'. |
84
| tests.c:13:40:13:43 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'long long'. |

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

Copy file name to clipboardExpand all lines: cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/tests.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void f(UNKNOWN_CHAR * str) {
99
sprintf(0, "%s", ""); // GOOD
1010
fprintf(0, "%s", ""); // GOOD
1111
printf("%s", str); // GOOD: erroneous type is ignored
12-
printf("%d %d %u %u", 42l, 42ul, 42l, 42ul); // BAD (FP)
12+
printf("%d %d %u %u", 42l, 42ul, 42l, 42ul); // GOOD: build mode none
1313
printf("%d %d %u %u", 42ll, 42ull, 42ll, 42ull); // BAD
1414
printf("%ld %ld %lu %lu", 42, 42u, 42, 42u); // BAD
1515
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.