Skip to content

Commit a656c69

Browse files
authored
Merge pull request #752 from jbj/large-parameter-assignment
C++: Exclude copy assignment in LargeParameter.ql
2 parents 04c1502 + 1cc36dd commit a656c69

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cpp/ql/src/Critical/LargeParameter.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ where f.getAParameter() = p
1818
and t.getSize() = size
1919
and size > 64
2020
and not t.getUnderlyingType() instanceof ArrayType
21+
and not f instanceof CopyAssignmentOperator
2122
select
2223
p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a pointer/reference instead.",
2324
t, t.toString()

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ void myFunction2(mySmallStruct *a, myLargeStruct *b) // GOOD
4444
void myFunction3(mySmallStruct &a, myLargeStruct &b) // GOOD
4545
{
4646
}
47+
48+
struct CustomAssignmentOp {
49+
// GOOD: it's an accepted pattern to implement copy assignment via copy and
50+
// swap. This delegates the resource management involved in copying to the
51+
// copy constructor so that logic only has to be written once.
52+
CustomAssignmentOp &operator=(CustomAssignmentOp rhs);
53+
char data[4096];
54+
};

0 commit comments

Comments
 (0)