Skip to content

Commit 55a7adf

Browse files
committed
C++: Make the message clearer.
1 parent b911556 commit 55a7adf

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313

1414
import cpp
1515

16-
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given
16+
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given, string ffcName
1717
where
1818
ffc = fl.getUse() and
1919
expected = fl.getNumArgNeeded() and
2020
given = ffc.getNumFormatArgument() and
2121
expected < given and
22-
fl.specsAreKnown()
23-
select ffc, "Format expects " + expected.toString() + " arguments but given " + given.toString()
22+
fl.specsAreKnown() and
23+
(
24+
if ffc.isInMacroExpansion()
25+
then ffcName = ffc.getTarget().getName() + " (in a macro expansion)"
26+
else ffcName = ffc.getTarget().getName()
27+
)
28+
select ffc,
29+
"Format for " + ffcName + " expects " + expected.toString() + " arguments but given " +
30+
given.toString()

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616

1717
import cpp
1818

19-
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given
19+
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given, string ffcName
2020
where
2121
ffc = fl.getUse() and
2222
expected = fl.getNumArgNeeded() and
2323
given = ffc.getNumFormatArgument() and
2424
expected > given and
25-
fl.specsAreKnown()
26-
select ffc, "Format expects " + expected.toString() + " arguments but given " + given.toString()
25+
fl.specsAreKnown() and
26+
(
27+
if ffc.isInMacroExpansion()
28+
then ffcName = ffc.getTarget().getName() + " (in a macro expansion)"
29+
else ffcName = ffc.getTarget().getName()
30+
)
31+
select ffc,
32+
"Format for " + ffcName + " expects " + expected.toString() + " arguments but given " +
33+
given.toString()
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
| a.c:18:3:18:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 2 |
2-
| b.c:15:3:15:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 2 |
3-
| c.c:7:3:7:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 2 |
4-
| custom_printf.cpp:31:5:31:12 | call to myPrintf | Format expects 2 arguments but given 3 |
5-
| macros.cpp:12:2:12:31 | call to printf | Format expects 2 arguments but given 3 |
6-
| macros.cpp:16:2:16:30 | call to printf | Format expects 2 arguments but given 3 |
7-
| test.c:7:2:7:7 | call to printf | Format expects 0 arguments but given 1 |
8-
| test.c:21:2:21:7 | call to printf | Format expects 2 arguments but given 3 |
9-
| test.c:27:3:27:8 | call to printf | Format expects 2 arguments but given 3 |
10-
| test.c:31:3:31:8 | call to printf | Format expects 1 arguments but given 3 |
11-
| test.c:32:3:32:8 | call to printf | Format expects 1 arguments but given 2 |
12-
| test.c:39:3:39:8 | call to printf | Format expects 2 arguments but given 5 |
13-
| test.c:40:3:40:8 | call to printf | Format expects 2 arguments but given 4 |
14-
| test.c:41:3:41:8 | call to printf | Format expects 2 arguments but given 3 |
1+
| a.c:18:3:18:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 2 |
2+
| b.c:15:3:15:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 2 |
3+
| c.c:7:3:7:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 2 |
4+
| custom_printf.cpp:31:5:31:12 | call to myPrintf | Format for myPrintf expects 2 arguments but given 3 |
5+
| macros.cpp:12:2:12:31 | call to printf | Format for printf (in a macro expansion) expects 2 arguments but given 3 |
6+
| macros.cpp:16:2:16:30 | call to printf | Format for printf (in a macro expansion) expects 2 arguments but given 3 |
7+
| test.c:7:2:7:7 | call to printf | Format for printf expects 0 arguments but given 1 |
8+
| test.c:21:2:21:7 | call to printf | Format for printf expects 2 arguments but given 3 |
9+
| test.c:27:3:27:8 | call to printf | Format for printf expects 2 arguments but given 3 |
10+
| test.c:31:3:31:8 | call to printf | Format for printf expects 1 arguments but given 3 |
11+
| test.c:32:3:32:8 | call to printf | Format for printf expects 1 arguments but given 2 |
12+
| test.c:39:3:39:8 | call to printf | Format for printf expects 2 arguments but given 5 |
13+
| test.c:40:3:40:8 | call to printf | Format for printf expects 2 arguments but given 4 |
14+
| test.c:41:3:41:8 | call to printf | Format for printf expects 2 arguments but given 3 |
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
| a.c:16:3:16:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 0 |
2-
| b.c:13:3:13:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 0 |
3-
| c.c:5:3:5:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 0 |
4-
| custom_printf.cpp:29:5:29:12 | call to myPrintf | Format expects 2 arguments but given 1 |
5-
| macros.cpp:14:2:14:37 | call to printf | Format expects 4 arguments but given 3 |
6-
| macros.cpp:21:2:21:36 | call to printf | Format expects 4 arguments but given 3 |
7-
| macros.cpp:32:2:32:25 | call to printf | Format expects 1 arguments but given 0 |
8-
| test.c:9:2:9:7 | call to printf | Format expects 1 arguments but given 0 |
9-
| test.c:12:2:12:7 | call to printf | Format expects 2 arguments but given 1 |
10-
| test.c:15:2:15:7 | call to printf | Format expects 3 arguments but given 2 |
11-
| test.c:19:2:19:7 | call to printf | Format expects 2 arguments but given 1 |
12-
| test.c:29:3:29:8 | call to printf | Format expects 2 arguments but given 1 |
1+
| a.c:16:3:16:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 0 |
2+
| b.c:13:3:13:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 0 |
3+
| c.c:5:3:5:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 0 |
4+
| custom_printf.cpp:29:5:29:12 | call to myPrintf | Format for myPrintf expects 2 arguments but given 1 |
5+
| macros.cpp:14:2:14:37 | call to printf | Format for printf (in a macro expansion) expects 4 arguments but given 3 |
6+
| macros.cpp:21:2:21:36 | call to printf | Format for printf (in a macro expansion) expects 4 arguments but given 3 |
7+
| macros.cpp:32:2:32:25 | call to printf | Format for printf (in a macro expansion) expects 1 arguments but given 0 |
8+
| test.c:9:2:9:7 | call to printf | Format for printf expects 1 arguments but given 0 |
9+
| test.c:12:2:12:7 | call to printf | Format for printf expects 2 arguments but given 1 |
10+
| test.c:15:2:15:7 | call to printf | Format for printf expects 3 arguments but given 2 |
11+
| test.c:19:2:19:7 | call to printf | Format for printf expects 2 arguments but given 1 |
12+
| test.c:29:3:29:8 | call to printf | Format for printf expects 2 arguments but given 1 |

0 commit comments

Comments
 (0)