Skip to content

Commit 1cc36dd

Browse files
committed
C++: Exclude copy assignment in LargeParameter.ql
The purpose of the copy assignment operator is to copy the object, so we should not complain that a copy happens when passing the parameter. See https://en.wikibooks.org/wiki/More_C++_Idioms/Copy-and-swap for details.
1 parent 4ea3849 commit 1cc36dd

File tree

3 files changed

+2
-2
lines changed

3 files changed

+2
-2
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()
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
| test.cpp:16:13:16:14 | _t | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:6:8:6:20 | myLargeStruct | myLargeStruct |
22
| test.cpp:24:44:24:48 | mtc_t | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:11:7:11:21 | myTemplateClass<myLargeStruct> | myTemplateClass<myLargeStruct> |
33
| test.cpp:28:49:28:49 | b | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:6:8:6:20 | myLargeStruct | myLargeStruct |
4-
| test.cpp:52:52:52:54 | rhs | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:48:8:48:25 | CustomAssignmentOp | CustomAssignmentOp |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ struct CustomAssignmentOp {
4949
// GOOD: it's an accepted pattern to implement copy assignment via copy and
5050
// swap. This delegates the resource management involved in copying to the
5151
// copy constructor so that logic only has to be written once.
52-
CustomAssignmentOp &operator=(CustomAssignmentOp rhs); // FALSE POSITIVE
52+
CustomAssignmentOp &operator=(CustomAssignmentOp rhs);
5353
char data[4096];
5454
};

0 commit comments

Comments
 (0)