Skip to content

Commit 9d15e67

Browse files
jbjgeoffw0
authored andcommitted
C++: Use variableAccessedAsValue in LargeParameter
Using `variableAccessedAsValue` fixes a FP because we can now distinguish modifications to the parameter from modifications to data _reachable from_ the parameter.
1 parent 60494fd commit 9d15e67

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

cpp/ql/src/Critical/LargeParameter.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ where f.getAParameter() = p
2222
and not f instanceof CopyAssignmentOperator
2323
// exception: p is written to, which may mean the copy is intended
2424
and not p.getAnAccess().isAddressOfAccessNonConst()
25-
and not exists(Access a |
26-
a.getTarget() = p and
25+
and not exists(Expr e |
26+
variableAccessedAsValue(p.getAnAccess(), e.getFullyConverted()) and
2727
(
28-
exists(Assignment an | an.getLValue().getAChild*() = a) or
29-
exists(CrementOperation co | co.getOperand().getAChild*() = a) or
30-
exists(FunctionCall fc | fc.getQualifier().getAChild*() = a and not fc.getTarget().hasSpecifier("const"))
28+
exists(Assignment an | an.getLValue() = e) or
29+
exists(CrementOperation co | co.getOperand() = e) or
30+
exists(FunctionCall fc | fc.getQualifier() = e and not fc.getTarget().hasSpecifier("const"))
3131
)
3232
)
3333
// if there's no block, we can't tell how the parameter is used

cpp/ql/test/query-tests/Critical/LargeParameter/LargeParameter.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
| test.cpp:107:16:107:16 | d | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
88
| test.cpp:108:16:108:16 | e | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
99
| test.cpp:109:16:109:16 | f | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
10+
| test.cpp:161:7:161:7 | b | This parameter of type $@ is 3208 bytes - consider passing a const pointer/reference instead. | test.cpp:153:8:153:10 | big | big |

cpp/ql/test/query-tests/Critical/LargeParameter/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct big
158158

159159
void myFunction7(
160160
big a, // GOOD
161-
big b // BAD [NOT DETECTED]
161+
big b // BAD
162162
)
163163
{
164164
a.xs[0]++; // modifies a

0 commit comments

Comments
 (0)