Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2def0ee

Browse files
committed
[CPP-340] Re-work QL query; treat undeclared C functions the same way as
()-declared functions.
1 parent 5d8b84c commit 2def0ee

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

cpp/ql/src/Likely Bugs/Likely Typos/FutileParams.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ from FunctionCall fc, Function f
1717
/* There must be a zero-parameter declaration */
1818
and exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | fde.getNumberOfParameters() = 0)
1919
/* There must be a mismatch between number of call arguments and number of parameters in some
20-
* non-implicit declaration of Function f
20+
* declaration of Function f
2121
*/
22-
and exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | not fde.isImplicit() and fde.getNumberOfParameters() != fc.getNumberOfArguments())
23-
/* There must be no _definition_ of Function f whose number of parameters matches number of call arguments */
24-
and not exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | fde.isDefinition() and fde.getNumberOfParameters() = fc.getNumberOfArguments())
25-
select fc
22+
and exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | fde.getNumberOfParameters() != fc.getNumberOfArguments())
23+
/* There must be no actual declaration of Function f whose number of parameters matches number of call arguments */
24+
and not exists ( FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | not fde.isImplicit() and fde.getNumberOfParameters() = fc.getNumberOfArguments())
25+
select fc, "This call has arguments, but $@ is not declared with any parameters.", f, f.toString()
2626

2727

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
| test.c:7:3:7:16 | call to declared_empty |
2-
| test.c:16:3:16:19 | call to not_yet_declared1 |
3-
| test.c:19:3:19:29 | call to declared_empty_defined_with |
4-
| test.c:24:3:24:29 | call to declared_empty_defined_with |
1+
| 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 |
2+
| 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 |
3+
| 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 |
4+
| 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 |
5+
| 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 |
6+
| 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 |

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/FutileParams/test.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ void test() {
88
declared_void(); // GOOD
99
declared_with(1); // GOOD
1010

11-
declared_ellipsis(); // GOOD
12-
declared_ellipsis(2); // GOOD
13-
14-
undeclared(1); // GOOD
11+
undeclared(); // GOOD
12+
undeclared(1); // BAD
1513

1614
not_yet_declared1(1); // BAD
1715
not_yet_declared2(1); // GOOD

0 commit comments

Comments
 (0)