зеркало из https://github.com/github/codeql.git
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.
This commit is contained in:
Родитель
6243c722c6
Коммит
ac249cdbbe
|
@ -8,6 +8,6 @@ int doFoo(Names n) { //wrong: n is passed by value (meaning the entire structure
|
|||
...
|
||||
}
|
||||
|
||||
int doBar(Names &n) { //better, only a reference is passed
|
||||
int doBar(const Names &n) { //better, only a reference is passed
|
||||
...
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @name Large object passed by value
|
||||
* @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.
|
||||
* @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.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @precision high
|
||||
|
@ -20,5 +20,5 @@ where f.getAParameter() = p
|
|||
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.",
|
||||
p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a const pointer/reference instead.",
|
||||
t, t.toString()
|
||||
|
|
Загрузка…
Ссылка в новой задаче