Skip to content

codeql: detect swapped decl/def function parameters #5145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/codeql/nightly/AccountVTableMismatch.ql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @kind problem
* @problem.severity warning
* @precision high
* @id asymmetric-research/account-meta-deref-before-modify
* @id asymmetric-research/account-vtable-mismatch
*/

import cpp
Expand Down
23 changes: 23 additions & 0 deletions contrib/codeql/nightly/SwappedParameters.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @name Swapped Parameters
* @description Detects cases where the parameters of a function are
* swapped between the function definition and the function
* implementation. If the both parameters are the same type and have the
* the compiler will not warn about it, but this confusion can easily
* lead to bugs.
* @kind problem
* @problem.severity warning
* @precision high
* @id asymmetric-research/swapped-parameters
*/

import cpp
import filter

from Function f, ParameterDeclarationEntry defP, Parameter implP
where included(f.getLocation()) and
implP = f.getAParameter() and
defP = f.getADeclarationEntry().getAParameterDeclarationEntry() and
defP.getName() = implP.getName() and
defP.getIndex() != implP.getIndex()
select defP, "Parameter " + defP.getName() + " is swapped with parameter " + implP.getName() + " in function " + f.getName() + "."
Loading