mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
[CPP-340] Re-work QL query; treat undeclared C functions the same way as
()-declared functions.
This commit is contained in:
@@ -17,11 +17,11 @@ from FunctionCall fc, Function f
|
||||
/* There must be a zero-parameter declaration */
|
||||
and exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | fde.getNumberOfParameters() = 0)
|
||||
/* There must be a mismatch between number of call arguments and number of parameters in some
|
||||
* non-implicit declaration of Function f
|
||||
* declaration of Function f
|
||||
*/
|
||||
and exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | not fde.isImplicit() and fde.getNumberOfParameters() != fc.getNumberOfArguments())
|
||||
/* There must be no _definition_ of Function f whose number of parameters matches number of call arguments */
|
||||
and not exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | fde.isDefinition() and fde.getNumberOfParameters() = fc.getNumberOfArguments())
|
||||
select fc
|
||||
and exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | fde.getNumberOfParameters() != fc.getNumberOfArguments())
|
||||
/* There must be no actual declaration of Function f whose number of parameters matches number of call arguments */
|
||||
and not exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | not fde.isImplicit() and fde.getNumberOfParameters() = fc.getNumberOfArguments())
|
||||
select fc, "This call has arguments, but $@ is not declared with any parameters.", f, f.toString()
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
| test.c:7:3:7:16 | call to declared_empty |
|
||||
| test.c:16:3:16:19 | call to not_yet_declared1 |
|
||||
| test.c:19:3:19:29 | call to declared_empty_defined_with |
|
||||
| test.c:24:3:24:29 | call to declared_empty_defined_with |
|
||||
| test.c:7:3:7:16 | call to declared_empty | This call has arguments, but $@ is not declared with any parameters. | test.c:1:6:1:19 | declared_empty | declared_empty |
|
||||
| test.c:12:3:12:12 | call to undeclared | This call has arguments, but $@ is not declared with any parameters. | test.c:11:3:11:3 | undeclared | undeclared |
|
||||
| test.c:14:3:14:19 | call to not_yet_declared1 | This call has arguments, but $@ is not declared with any parameters. | test.c:14:3:14:3 | not_yet_declared1 | not_yet_declared1 |
|
||||
| test.c:14:3:14:19 | call to not_yet_declared1 | This call has arguments, but $@ is not declared with any parameters. | test.c:25:6:25:22 | not_yet_declared1 | not_yet_declared1 |
|
||||
| test.c:17:3:17:29 | call to declared_empty_defined_with | This call has arguments, but $@ is not declared with any parameters. | test.c:27:6:27:32 | declared_empty_defined_with | declared_empty_defined_with |
|
||||
| test.c:22:3:22:29 | call to declared_empty_defined_with | This call has arguments, but $@ is not declared with any parameters. | test.c:27:6:27:32 | declared_empty_defined_with | declared_empty_defined_with |
|
||||
|
||||
@@ -8,10 +8,8 @@ void test() {
|
||||
declared_void(); // GOOD
|
||||
declared_with(1); // GOOD
|
||||
|
||||
declared_ellipsis(); // GOOD
|
||||
declared_ellipsis(2); // GOOD
|
||||
|
||||
undeclared(1); // GOOD
|
||||
undeclared(); // GOOD
|
||||
undeclared(1); // BAD
|
||||
|
||||
not_yet_declared1(1); // BAD
|
||||
not_yet_declared2(1); // GOOD
|
||||
|
||||
Reference in New Issue
Block a user