diff --git a/cpp/ql/src/Critical/LargeParameter.ql b/cpp/ql/src/Critical/LargeParameter.ql index 1571e96bbec9..c2fd1053ae07 100644 --- a/cpp/ql/src/Critical/LargeParameter.ql +++ b/cpp/ql/src/Critical/LargeParameter.ql @@ -18,6 +18,7 @@ where f.getAParameter() = p and t.getSize() = size and size > 64 and not t.getUnderlyingType() instanceof ArrayType + and not f instanceof CopyAssignmentOperator select p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a pointer/reference instead.", t, t.toString() diff --git a/cpp/ql/test/query-tests/Critical/LargeParameter/test.cpp b/cpp/ql/test/query-tests/Critical/LargeParameter/test.cpp index 334eeadf4484..cc9c217f9f9e 100644 --- a/cpp/ql/test/query-tests/Critical/LargeParameter/test.cpp +++ b/cpp/ql/test/query-tests/Critical/LargeParameter/test.cpp @@ -44,3 +44,11 @@ void myFunction2(mySmallStruct *a, myLargeStruct *b) // GOOD void myFunction3(mySmallStruct &a, myLargeStruct &b) // GOOD { } + +struct CustomAssignmentOp { + // GOOD: it's an accepted pattern to implement copy assignment via copy and + // swap. This delegates the resource management involved in copying to the + // copy constructor so that logic only has to be written once. + CustomAssignmentOp &operator=(CustomAssignmentOp rhs); + char data[4096]; +};