Skip to content

Commit 9ea2941

Browse files
committed
codeql: detect swapped decl/def function parameters
Written to detect variants of #4900 in ci. Found #5129 locally. Drive-by: fix id of recent vtable query.
1 parent 9c0bbf1 commit 9ea2941

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

contrib/codeql/nightly/AccountVTableMismatch.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @kind problem
66
* @problem.severity warning
77
* @precision high
8-
* @id asymmetric-research/account-meta-deref-before-modify
8+
* @id asymmetric-research/account-vtable-mismatch
99
*/
1010

1111
import cpp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @name Swapped Parameters
3+
* @description Detects cases where the parameters of a function are
4+
* swapped between the function definition and the function
5+
* implementation. If the both parameters are the same type and have the
6+
* the compiler will not warn about it, but this confusion can easily
7+
* lead to bugs.
8+
* @kind problem
9+
* @problem.severity warning
10+
* @precision high
11+
* @id asymmetric-research/swapped-parameters
12+
*/
13+
14+
import cpp
15+
import filter
16+
17+
from Function f, ParameterDeclarationEntry defP, Parameter implP
18+
where included(f.getLocation()) and
19+
implP = f.getAParameter() and
20+
defP = f.getADeclarationEntry().getAParameterDeclarationEntry() and
21+
defP.getName() = implP.getName() and
22+
defP.getIndex() != implP.getIndex()
23+
select defP, implP

0 commit comments

Comments
 (0)