Skip to content

Commit ac249cd

Browse files
committed
Fix reccomendation for LargeParameter (C++)
The previous reccomentation changed the behaviour of the code. A user following the advice might have broken her/his code: With call-by-value, the original parameter is not changed. With a call-by-reference, however, it may be changed. To be sure, nothing breaks by blindly following the advice, suggest to pass a const reference.
1 parent 6243c72 commit ac249cd

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cpp/ql/src/Critical/LargeParameter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ int doFoo(Names n) { //wrong: n is passed by value (meaning the entire structure
88
...
99
}
1010

11-
int doBar(Names &n) { //better, only a reference is passed
11+
int doBar(const Names &n) { //better, only a reference is passed
1212
...
1313
}

cpp/ql/src/Critical/LargeParameter.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Large object passed by value
3-
* @description An object larger than 64 bytes is passed by value to a function. Passing large objects by value unnecessarily use up scarce stack space, increase the cost of calling a function and can be a security risk. Use a pointer to the object instead.
3+
* @description An object larger than 64 bytes is passed by value to a function. Passing large objects by value unnecessarily use up scarce stack space, increase the cost of calling a function and can be a security risk. Use a const pointer to the object instead.
44
* @kind problem
55
* @problem.severity warning
66
* @precision high
@@ -20,5 +20,5 @@ where f.getAParameter() = p
2020
and not t.getUnderlyingType() instanceof ArrayType
2121
and not f instanceof CopyAssignmentOperator
2222
select
23-
p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a pointer/reference instead.",
23+
p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a const pointer/reference instead.",
2424
t, t.toString()

0 commit comments

Comments
 (0)