File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,20 @@ class UnnamedParameter extends Parameter {
2222 UnnamedParameter ( ) { not this .isNamed ( ) }
2323}
2424
25+ /*
26+ * This is a copy of the private `hasZeroParamDecl` predicate from the standard set of
27+ * queries as of the `codeql-cli/2.11.2` tag in `github/codeql`.
28+ */
29+
30+ predicate hasZeroParamDecl ( Function f ) {
31+ exists ( FunctionDeclarationEntry fde | fde = f .getADeclarationEntry ( ) |
32+ not fde .isImplicit ( ) and
33+ not fde .hasVoidParamList ( ) and
34+ fde .getNumberOfParameters ( ) = 0 and
35+ not fde .isDefinition ( )
36+ )
37+ }
38+
2539from Function f , string msg
2640where
2741 not isExcluded ( f , Declarations4Package:: functionTypesNotInPrototypeFormQuery ( ) ) and
3044 f .getAParameter ( ) instanceof UnnamedParameter and
3145 msg = "Function " + f + " declares parameter that is unnamed."
3246 or
33- //void keyword not present in function signature, no way to tell which
34- not exists ( f .getAParameter ( ) ) and
35- msg =
36- "Function " + f +
37- " may not specify all parameter types or may not specifiy void for no parameters present."
47+ hasZeroParamDecl ( f ) and
48+ msg = "Function " + f + " does not specifiy void for no parameters present."
3849 or
3950 exists ( Parameter p |
4051 p .getFunction ( ) = f and
Original file line number Diff line number Diff line change 1- | test.c:2:6:2:7 | f0 | Function f0 may not specify all parameter types or may not specifiy void for no parameters present. |
21| test.c:3:6:3:7 | f1 | Function f1 declares parameter that is unnamed. |
3- | test.c:4:6:4:7 | f2 | Function f2 may not specify all parameter types or may not specifiy void for no parameters present. |
4- | test.c:5:6:5:7 | f3 | Function f3 may not specify all parameter types or may not specifiy void for no parameters present. |
2+ | test.c:4:6:4:7 | f2 | Function f2 does not specifiy void for no parameters present. |
3+ | test.c:5:6:5:7 | f3 | Function f3 does not specifiy void for no parameters present. |
54| test.c:7:5:7:6 | f5 | Function f5 declares parameter in unsupported declaration list. |
Original file line number Diff line number Diff line change 11void f (int x ); // COMPLIANT
2- void f0 (void ); // COMPLIANT[FALSE_POSITIVE]
2+ void f0 (void ); // COMPLIANT
33void f1 (int ); // NON_COMPLIANT
44void f2 (); // NON_COMPLIANT
55void f3 (x ); // NON_COMPLIANT
You can’t perform that action at this time.
0 commit comments