Skip to content

Commit c0d29f2

Browse files
committed
Initial refactor to address false positives in sizeof misuse queries.
1 parent eba5208 commit c0d29f2

File tree

8 files changed

+108
-114
lines changed

8 files changed

+108
-114
lines changed

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,7 @@
1111
import cpp
1212
import SizeOfTypeUtils
1313

14-
/**
15-
* Windows SDK corecrt_math.h defines a macro _CLASS_ARG that
16-
* intentionally misuses sizeof to determine the size of a floating point type.
17-
* Explicitly ignoring any hit in this macro.
18-
*/
19-
predicate isPartOfCrtFloatingPointMacroExpansion(Expr e) {
20-
exists(MacroInvocation mi |
21-
mi.getMacroName() = "_CLASS_ARG" and
22-
mi.getMacro().getFile().getBaseName() = "corecrt_math.h" and
23-
mi.getAnExpandedElement() = e
24-
)
25-
}
26-
27-
/**
28-
* Determines if the sizeOfExpr is ignorable.
29-
*/
30-
predicate ignorableSizeof(SizeofExprOperator sizeofExpr) {
31-
// a common pattern found is to sizeof a binary operation to check a type
32-
// to then perfomr an onperaiton for a 32 or 64 bit type.
33-
// these cases often look like sizeof(x) >=4
34-
// more generally we see binary operations frequently used in different type
35-
// checks, where the sizeof is part of some comparison operation of a switch statement guard.
36-
// sizeof as an argument is also similarly used, but seemingly less frequently.
37-
exists(ComparisonOperation comp | comp.getAnOperand() = sizeofExpr)
38-
or
39-
exists(ConditionalStmt s | s.getControllingExpr() = sizeofExpr)
40-
or
41-
// another common practice is to use bit-wise operations in sizeof to allow the compiler to
42-
// 'pack' the size appropriate but get the size of the result out of a sizeof operation.
43-
sizeofExpr.getExprOperand() instanceof BinaryBitwiseOperation
44-
}
45-
46-
from SizeofExprOperator sizeofExpr, string message, Expr op
14+
from CandidateSizeofCall sizeofExpr, string message, Expr op
4715
where
4816
exists(string tmpMsg |
4917
(
@@ -55,8 +23,6 @@ where
5523
then message = tmpMsg + "(in a macro expansion)"
5624
else message = tmpMsg
5725
) and
58-
op = sizeofExpr.getExprOperand() and
59-
not isPartOfCrtFloatingPointMacroExpansion(op) and
60-
not ignorableSizeof(sizeofExpr)
26+
op = sizeofExpr.getExprOperand()
6127
select sizeofExpr, "$@: $@ of $@ inside sizeof.", sizeofExpr, message,
6228
sizeofExpr.getEnclosingFunction(), "Usage", op, message

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

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,38 @@
1111
import cpp
1212
import SizeOfTypeUtils
1313

14-
predicate isExprAConstInteger(Expr e, MacroInvocation mi) {
15-
exists(Type type |
16-
type = e.getExplicitlyConverted().getType() and
17-
isTypeDangerousForSizeof(type) and
18-
// Special case for wide-char literals when the compiler doesn't recognize wchar_t (i.e. L'\\', L'\0')
19-
// Accounting for parenthesis "()" around the value
20-
not exists(Macro m | m = mi.getMacro() |
21-
m.getBody().toString().regexpMatch("^[\\s(]*L'.+'[\\s)]*$")
22-
) and
23-
// Special case for token pasting operator
24-
not exists(Macro m | m = mi.getMacro() | m.getBody().toString().regexpMatch("^.*\\s*##\\s*.*$")) and
25-
// Special case for multichar literal integers that are exactly 4 character long (i.e. 'val1')
26-
not exists(Macro m | m = mi.getMacro() |
27-
e.getType().toString() = "int" and
28-
m.getBody().toString().regexpMatch("^'.{4}'$")
29-
) and
30-
e.isConstant()
31-
)
32-
}
33-
3414
int countMacros(Expr e) { result = count(MacroInvocation mi | mi.getExpr() = e | mi) }
3515

3616
predicate isSizeOfExprOperandMacroInvocationAConstInteger(
37-
SizeofExprOperator sizeofExpr, MacroInvocation mi
17+
CandidateSizeofCall sizeofExpr, MacroInvocation mi, Literal l
3818
) {
39-
exists(Expr e |
40-
e = mi.getExpr() and
41-
e = sizeofExpr.getExprOperand() and
42-
isExprAConstInteger(e, mi) and
43-
// Special case for FPs that involve an inner macro that resolves to 0 such as _T('\0')
44-
not exists(int macroCount | macroCount = countMacros(e) |
45-
macroCount > 1 and e.(Literal).getValue().toInt() = 0
46-
)
47-
)
19+
isTypeDangerousForSizeof(sizeofExpr.getExprOperand()) and
20+
l = mi.getExpr() and
21+
l = sizeofExpr.getExprOperand() and
22+
mi.getExpr() = l and
23+
// Special case for FPs that involve an inner macro that resolves to 0 such as _T('\0')
24+
// i.e., if a macro resolves to 0, the same 0 expression cannot be the macro
25+
// resolution of another macro invocation (a nested invocation).
26+
// Count the number of invocations resolving to the same literal, if >1, ignore.
27+
not exists(int macroCount | macroCount = countMacros(l) |
28+
macroCount > 1 and l.getValue().toInt() = 0
29+
) and
30+
// Special case for wide-char literals when the compiler doesn't recognize wchar_t (i.e. L'\\', L'\0')
31+
// Accounting for parenthesis "()" around the value
32+
not exists(Macro m | m = mi.getMacro() |
33+
m.getBody().toString().regexpMatch("^[\\s(]*L'.+'[\\s)]*$")
34+
) and
35+
// Special case for token pasting operator
36+
not exists(Macro m | m = mi.getMacro() | m.getBody().toString().regexpMatch("^.*\\s*##\\s*.*$")) and
37+
// Special case for multichar literal integers that are exactly 4 character long (i.e. 'val1')
38+
not exists(Macro m | m = mi.getMacro() | m.getBody().toString().regexpMatch("^'.{4}'$"))
4839
}
4940

50-
from SizeofExprOperator sizeofExpr, MacroInvocation mi
51-
where isSizeOfExprOperandMacroInvocationAConstInteger(sizeofExpr, mi)
41+
from CandidateSizeofCall sizeofExpr, MacroInvocation mi, string inMacro
42+
where
43+
isSizeOfExprOperandMacroInvocationAConstInteger(sizeofExpr, mi, _) and
44+
(if sizeofExpr.isInMacroExpansion() then inMacro = " (in a macro expansion) " else inMacro = " ")
5245
select sizeofExpr,
53-
"$@: sizeof of integer macro $@ will always return the size of the underlying integer type.",
54-
sizeofExpr, sizeofExpr.getEnclosingFunction().getName(), mi.getMacro(), mi.getMacro().getName()
46+
"$@: sizeof" + inMacro +
47+
"of integer macro $@ will always return the size of the underlying integer type.", sizeofExpr,
48+
sizeofExpr.getEnclosingFunction().getName(), mi.getMacro(), mi.getMacro().getName()

cpp/ql/src/Microsoft/Likely Bugs/SizeOfMisuse/SizeOfTypeUtils.qll

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,83 @@
11
import cpp
22

33
/**
4-
* Holds if `type` is a `Type` that typically should not be used for `sizeof` in macros or function return values.
4+
* Determines if the sizeOfExpr is ignorable.
55
*/
6-
predicate isTypeDangerousForSizeof(Type type) {
7-
(
8-
type instanceof IntegralOrEnumType and
9-
// ignore string literals
10-
not type instanceof WideCharType and
11-
not type instanceof CharType
6+
predicate ignorableSizeof(SizeofExprOperator sizeofExpr) {
7+
// a common pattern found is to sizeof a binary operation to check a type
8+
// to then perfomr an onperaiton for a 32 or 64 bit type.
9+
// these cases often look like sizeof(x) >=4
10+
// more generally we see binary operations frequently used in different type
11+
// checks, where the sizeof is part of some comparison operation of a switch statement guard.
12+
// sizeof as an argument is also similarly used, but seemingly less frequently.
13+
exists(ComparisonOperation comp | comp.getAnOperand() = sizeofExpr)
14+
or
15+
exists(ConditionalStmt s | s.getControllingExpr() = sizeofExpr)
16+
or
17+
// another common practice is to use bit-wise operations in sizeof to allow the compiler to
18+
// 'pack' the size appropriate but get the size of the result out of a sizeof operation.
19+
sizeofExpr.getExprOperand() instanceof BinaryBitwiseOperation
20+
or
21+
// Known intentional misuses in corecrt_math.h
22+
// Windows SDK corecrt_math.h defines a macro _CLASS_ARG that
23+
// intentionally misuses sizeof to determine the size of a floating point type.
24+
// Explicitly ignoring any hit in this macro.
25+
exists(MacroInvocation mi |
26+
mi.getMacroName() = "_CLASS_ARG" and
27+
mi.getMacro().getFile().getBaseName() = "corecrt_math.h" and
28+
mi.getAnExpandedElement() = sizeofExpr
29+
)
30+
or
31+
// the linux minmax.h header has macros that intentionally miuse sizeof,
32+
// for type checking, see __typecheck
33+
// This code has been observed in kernel.h as well.
34+
// Ignoring cases in linux build_bug.h and bug.h see BUILD_BUG_ON_INVALID
35+
// Ignoring cases of uses of FP_XSTATE_MAGIC2_SIZE found in sigcontext.h
36+
// which uses sizeof a constant as a way to get an architecturally agnostic size by
37+
// using the special magic number constant already defined
38+
exists(MacroInvocation mi |
39+
(
40+
mi.getMacro().getFile().getBaseName() in [
41+
"minmax.h", "build_bug.h", "kernel.h", "bug.h", "sigcontext.h"
42+
] and
43+
mi.getMacro().getFile().getRelativePath().toLowerCase().matches("%linux%")
44+
) and
45+
mi.getAnExpandedElement() = sizeofExpr
46+
)
47+
or
48+
// if the operand is a macro invocation of something resembling "null"
49+
// assume sizeof is intended for strings, and ignore as this is a
50+
// potential null pointer issue, not a misuse of sizeof.
51+
exists(MacroInvocation mi |
52+
mi.getAnExpandedElement() = sizeofExpr.getExprOperand() and
53+
mi.getMacroName().toLowerCase().matches("%null%")
1254
)
55+
or
56+
// LLVM has known test cases under gcc-torture, ignore any hits under any matching directory
57+
// see for example 20020226-1.c
58+
sizeofExpr.getFile().getRelativePath().toLowerCase().matches("%gcc-%torture%")
59+
}
60+
61+
class CandidateSizeofCall extends SizeofExprOperator {
62+
CandidateSizeofCall() { not ignorableSizeof(this) }
1363
}
1464

1565
/**
1666
* Holds if `type` is a `Type` that typically should not be used for `sizeof` in macros or function return values.
17-
* This predicate extends the types detected in exchange of precision.
18-
* For higher precision, please use `isTypeDangerousForSizeof`
1967
*/
20-
predicate isTypeDangerousForSizeofLowPrecision(Type type) {
21-
(
22-
// UINT8/BYTE are typedefs to char, so we treat them separately.
23-
// WCHAR is sometimes a typedef to UINT16, so we treat it separately too.
24-
type.getName() = "UINT8"
25-
or
26-
type.getName() = "BYTE"
27-
or
28-
not type.getName() = "WCHAR" and
29-
exists(Type ut |
30-
ut = type.getUnderlyingType() and
31-
ut instanceof IntegralOrEnumType and
32-
not ut instanceof WideCharType and
33-
not ut instanceof CharType
68+
predicate isTypeDangerousForSizeof(Expr e) {
69+
exists(Type type |
70+
(
71+
if e.getImplicitlyConverted().hasExplicitConversion()
72+
then type = e.getExplicitlyConverted().getType()
73+
else type = e.getUnspecifiedType()
74+
)
75+
|
76+
(
77+
type instanceof IntegralOrEnumType and
78+
// ignore string literals
79+
not type instanceof WideCharType and
80+
not type instanceof CharType
3481
)
3582
)
3683
}
37-
38-
/**
39-
* Holds if the `Function` return type is dangerous as input for `sizeof`.
40-
*/
41-
class FunctionWithTypeDangerousForSizeofLowPrecision extends Function {
42-
FunctionWithTypeDangerousForSizeofLowPrecision() {
43-
exists(Type type | type = this.getType() | isTypeDangerousForSizeofLowPrecision(type))
44-
}
45-
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
| test2.c:72:6:72:42 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.c:72:6:72:42 | sizeof(<expr>) | Test01 | test2.c:46:1:46:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS |
22
| test2.c:80:10:80:32 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.c:80:10:80:32 | sizeof(<expr>) | Test01 | test2.c:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST |
33
| test2.c:81:6:81:29 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.c:81:6:81:29 | sizeof(<expr>) | Test01 | test2.c:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 |
4-
| test2.c:89:7:89:35 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.c:89:7:89:35 | sizeof(<expr>) | Test01 | test2.c:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
5-
| test2.c:98:6:98:31 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.c:98:6:98:31 | sizeof(<expr>) | Test01 | test2.c:17:1:17:40 | #define SOME_SIZEOF_MACRO2 (sizeof(int)) | SOME_SIZEOF_MACRO2 |
4+
| test2.c:89:7:89:35 | sizeof(<expr>) | $@: sizeof (in a macro expansion) of integer macro $@ will always return the size of the underlying integer type. | test2.c:89:7:89:35 | sizeof(<expr>) | Test01 | test2.c:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
65
| test2.c:112:6:112:37 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.c:112:6:112:37 | sizeof(<expr>) | Test01 | test2.c:31:1:31:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 |
76
| test2.cpp:75:6:75:42 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.cpp:75:6:75:42 | sizeof(<expr>) | Test01 | test2.cpp:48:1:48:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS |
87
| test2.cpp:83:10:83:32 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.cpp:83:10:83:32 | sizeof(<expr>) | Test01 | test2.cpp:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST |
98
| test2.cpp:84:6:84:29 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.cpp:84:6:84:29 | sizeof(<expr>) | Test01 | test2.cpp:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 |
10-
| test2.cpp:92:7:92:35 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.cpp:92:7:92:35 | sizeof(<expr>) | Test01 | test2.cpp:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
11-
| test2.cpp:101:6:101:31 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.cpp:101:6:101:31 | sizeof(<expr>) | Test01 | test2.cpp:17:1:17:40 | #define SOME_SIZEOF_MACRO2 (sizeof(int)) | SOME_SIZEOF_MACRO2 |
9+
| test2.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. | test2.cpp:92:7:92:35 | sizeof(<expr>) | Test01 | test2.cpp:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
1210
| test2.cpp:116:6:116:37 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test2.cpp:116:6:116:37 | sizeof(<expr>) | Test01 | test2.cpp:32:1:32:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 |
1311
| test.c:72:6:72:42 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.c:72:6:72:42 | sizeof(<expr>) | Test01 | test.c:46:1:46:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS |
1412
| test.c:80:10:80:32 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.c:80:10:80:32 | sizeof(<expr>) | Test01 | test.c:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST |
1513
| test.c:81:6:81:29 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.c:81:6:81:29 | sizeof(<expr>) | Test01 | test.c:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 |
16-
| test.c:89:7:89:35 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.c:89:7:89:35 | sizeof(<expr>) | Test01 | test.c:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
17-
| test.c:98:6:98:31 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.c:98:6:98:31 | sizeof(<expr>) | Test01 | test.c:17:1:17:40 | #define SOME_SIZEOF_MACRO2 (sizeof(int)) | SOME_SIZEOF_MACRO2 |
14+
| test.c:89:7:89:35 | sizeof(<expr>) | $@: sizeof (in a macro expansion) of integer macro $@ will always return the size of the underlying integer type. | test.c:89:7:89:35 | sizeof(<expr>) | Test01 | test.c:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE |
1815
| test.c:112:6:112:37 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.c:112:6:112:37 | sizeof(<expr>) | Test01 | test.c:31:1:31:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 |
1916
| 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 |
2017
| 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 |
2118
| 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 |
22-
| test.cpp:92:7:92:35 | sizeof(<expr>) | $@: sizeof 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 |
23-
| test.cpp:101:6:101:31 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:101:6:101:31 | sizeof(<expr>) | Test01 | test.cpp:17:1:17:40 | #define SOME_SIZEOF_MACRO2 (sizeof(int)) | SOME_SIZEOF_MACRO2 |
19+
| 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 |
2420
| 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 |

cpp/ql/test/query-tests/Microsoft/Likely Bugs/SizeOfMisuse/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void Test01() {
9595
x = sizeof(SOME_SIZEOF_MACRO_CAST) * 3; //BUG: ArgumentIsSizeofOrOperation
9696

9797
x = SOME_SIZEOF_MACRO2; // GOOD
98-
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: SizeOfConstIntMacro, ArgumentIsSizeofOrOperation
98+
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: ArgumentIsSizeofOrOperation
9999

100100
x = sizeof(a) / sizeof(int); // GOOD
101101

cpp/ql/test/query-tests/Microsoft/Likely Bugs/SizeOfMisuse/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void Test01() {
9898
x = sizeof(SOME_SIZEOF_MACRO_CAST) * 3; //BUG: ArgumentIsSizeofOrOperation
9999

100100
x = SOME_SIZEOF_MACRO2; // GOOD
101-
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: SizeOfConstIntMacro, ArgumentIsSizeofOrOperation
101+
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: ArgumentIsSizeofOrOperation
102102

103103
x = sizeof(a) / sizeof(int); // GOOD
104104

cpp/ql/test/query-tests/Microsoft/Likely Bugs/SizeOfMisuse/test2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void Test01() {
9595
x = sizeof(SOME_SIZEOF_MACRO_CAST) * 3; //BUG: ArgumentIsSizeofOrOperation
9696

9797
x = SOME_SIZEOF_MACRO2; // GOOD
98-
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: SizeOfConstIntMacro, ArgumentIsSizeofOrOperation
98+
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: ArgumentIsSizeofOrOperation
9999

100100
x = sizeof(a) / sizeof(int); // GOOD
101101

cpp/ql/test/query-tests/Microsoft/Likely Bugs/SizeOfMisuse/test2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void Test01() {
9898
x = sizeof(SOME_SIZEOF_MACRO_CAST) * 3; //BUG: ArgumentIsSizeofOrOperation
9999

100100
x = SOME_SIZEOF_MACRO2; // GOOD
101-
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: SizeOfConstIntMacro, ArgumentIsSizeofOrOperation
101+
x = sizeof(SOME_SIZEOF_MACRO2); //BUG: ArgumentIsSizeofOrOperation
102102

103103
x = sizeof(a) / sizeof(int); // GOOD
104104

0 commit comments

Comments
 (0)