Skip to content

Commit a412b91

Browse files
committed
Simplifying sizeof query output messages, and making both consistent with each other.
1 parent d2cefd2 commit a412b91

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

cpp/ql/src/Microsoft/Likely Bugs/SizeOfMisuse/ArgumentIsSizeofOrOperation.ql

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,13 @@ class CandidateOperation extends Operation {
4646
}
4747
}
4848

49-
from CandidateSizeofCall sizeofExpr, string message, Expr op
49+
from CandidateSizeofCall sizeofExpr, string inMacro, string argType, Expr op
5050
where
51-
exists(string tmpMsg |
52-
(
53-
op instanceof CandidateOperation and tmpMsg = "binary operator"
54-
or
55-
op instanceof SizeofOperator and tmpMsg = "sizeof"
56-
) and
57-
if sizeofExpr.isInMacroExpansion()
58-
then message = tmpMsg + "(in a macro expansion)"
59-
else message = tmpMsg
51+
(
52+
op instanceof CandidateOperation and argType = "binary operator"
53+
or
54+
op instanceof SizeofOperator and argType = "sizeof operation"
6055
) and
56+
(if sizeofExpr.isInMacroExpansion() then inMacro = " (in a macro expansion) " else inMacro = " ") and
6157
op = sizeofExpr.getExprOperand()
62-
select sizeofExpr, "$@: $@ of $@ inside sizeof.", sizeofExpr, message,
63-
sizeofExpr.getEnclosingFunction(), "Usage", op, message
58+
select sizeofExpr, "sizeof" + inMacro + "has a " + argType + " argument: $@.", op, op.toString()

cpp/ql/src/Microsoft/Likely Bugs/SizeOfMisuse/SizeOfConstIntMacro.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ where
7272
isSizeOfExprOperandMacroInvocationAConstInteger(sizeofExpr, mi, _) and
7373
(if sizeofExpr.isInMacroExpansion() then inMacro = " (in a macro expansion) " else inMacro = " ")
7474
select sizeofExpr,
75-
"$@: sizeof" + inMacro +
76-
"of integer macro $@ will always return the size of the underlying integer type.", sizeofExpr,
77-
sizeofExpr.getEnclosingFunction().getName(), mi.getMacro(), mi.getMacro().getName()
75+
"sizeof" + inMacro +
76+
"of integer macro $@ will always return the size of the underlying integer type.",
77+
mi.getMacro(), mi.getMacro().getName()
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| test.cpp:89:6:89:29 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:89:6:89:29 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:89:13:89:28 | ... / ... | binary operator |
2-
| test.cpp:96:6:96:30 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:96:6:96:30 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:96:13:96:29 | ... * ... | binary operator |
3-
| test.cpp:98:6:98:35 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:98:6:98:35 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:98:13:98:34 | ... * ... | binary operator |
4-
| test.cpp:101:6:101:31 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:101:6:101:31 | sizeof(<expr>) | sizeof | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:101:13:101:30 | sizeof(int) | sizeof |
5-
| test.cpp:120:6:120:24 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:120:6:120:24 | sizeof(<expr>) | sizeof | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:120:13:120:23 | sizeof(int) | sizeof |
6-
| test.cpp:121:6:121:18 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:121:6:121:18 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:121:13:121:17 | ... + ... | binary operator |
1+
| test.cpp:89:6:89:29 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:89:13:89:28 | ... / ... | ... / ... |
2+
| test.cpp:96:6:96:30 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:96:13:96:29 | ... * ... | ... * ... |
3+
| test.cpp:98:6:98:35 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:98:13:98:34 | ... * ... | ... * ... |
4+
| test.cpp:101:6:101:31 | sizeof(<expr>) | sizeof has a sizeof operation argument: $@. | test.cpp:101:13:101:30 | sizeof(int) | sizeof(int) |
5+
| test.cpp:120:6:120:24 | sizeof(<expr>) | sizeof has a sizeof operation argument: $@. | test.cpp:120:13:120:23 | sizeof(int) | sizeof(int) |
6+
| test.cpp:121:6:121:18 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:121:13:121:17 | ... + ... | ... + ... |
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| test.cpp:75:6:75:42 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:75:6:75:42 | sizeof(<expr>) | Test01 | test.cpp:48:1:48:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS |
2-
| test.cpp:83:10:83:32 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:83:10:83:32 | sizeof(<expr>) | Test01 | test.cpp:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST |
3-
| test.cpp:84:6:84:29 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:84:6:84:29 | sizeof(<expr>) | Test01 | test.cpp:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 |
4-
| test.cpp:92:7:92:35 | sizeof(<expr>) | $@: sizeof (in a macro expansion) of integer macro $@ will always return the size of the underlying integer type. | test.cpp:92:7:92:35 | sizeof(<expr>) | Test01 | test.cpp:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
5-
| test.cpp:116:6:116:37 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:116:6:116:37 | sizeof(<expr>) | Test01 | test.cpp:32:1:32:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 |
1+
| test.cpp:75:6:75:42 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:48:1:48:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS |
2+
| test.cpp:83:10:83:32 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST |
3+
| test.cpp:84:6:84:29 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 |
4+
| test.cpp:92:7:92:35 | sizeof(<expr>) | sizeof (in a macro expansion) of integer macro $@ will always return the size of the underlying integer type. | test.cpp:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
5+
| test.cpp:116:6:116:37 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:32:1:32:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 |

0 commit comments

Comments
 (0)