-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17775 from github/calumgrant/bmn/wrong-type-forma…
…t-arguments-test C++: Reduce FPs in cpp/wrong-type-format-argument due to extraction errors
- Loading branch information
Showing
22 changed files
with
95 additions
and
29 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
cpp/ql/lib/change-notes/2014-10-16-implicitly-declared-fns.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
category: feature | ||
--- | ||
* Added the predicate `mayBeFromImplicitlyDeclaredFunction()` to the `Call` class to represent calls that may be the return value of an implicitly declared C function. | ||
* Added the predicate `getAnExplicitDeclarationEntry()` to the `Function` class to get a `FunctionDeclarationEntry` that is not implicit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
cpp/ql/src/change-notes/2024-10-15-wrong-type-format-argument.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* Remove results from the `cpp/wrong-type-format-argument` ("Wrong type of arguments to formatting function") query if the argument is the return value of an implicitly declared function. |
1 change: 1 addition & 0 deletions
1
cpp/ql/test/library-tests/exprs/implicitly_declared/error_type.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| file://:0:0:0:0 | <error expr> | |
5 changes: 5 additions & 0 deletions
5
cpp/ql/test/library-tests/exprs/implicitly_declared/error_type.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import cpp | ||
|
||
from Expr e | ||
where e.getType() instanceof ErroneousType | ||
select e |
2 changes: 2 additions & 0 deletions
2
cpp/ql/test/library-tests/exprs/implicitly_declared/errors.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| file://:0:0:0:0 | There was an error during this compilation | | ||
| implicit.cpp:5:5:5:5 | identifier 'g' is undefined | |
4 changes: 4 additions & 0 deletions
4
cpp/ql/test/library-tests/exprs/implicitly_declared/errors.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import cpp | ||
|
||
from Diagnostic d | ||
select d |
6 changes: 6 additions & 0 deletions
6
cpp/ql/test/library-tests/exprs/implicitly_declared/functions.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
| implicit2.c:1:7:1:7 | g | file://:0:0:0:0 | float | | ||
| implicit2.c:1:7:1:7 | g | file://:0:0:0:0 | int | | ||
| implicit.c:1:6:1:6 | f | file://:0:0:0:0 | void | | ||
| implicit.c:3:5:3:5 | g | file://:0:0:0:0 | float | | ||
| implicit.c:3:5:3:5 | g | file://:0:0:0:0 | int | | ||
| implicit.cpp:3:6:3:6 | f | file://:0:0:0:0 | void | |
5 changes: 5 additions & 0 deletions
5
cpp/ql/test/library-tests/exprs/implicitly_declared/functions.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import cpp | ||
|
||
from Function fn | ||
where fn.fromSource() | ||
select fn, fn.getType() |
4 changes: 4 additions & 0 deletions
4
cpp/ql/test/library-tests/exprs/implicitly_declared/implicit.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void f() { | ||
f(); | ||
g(); | ||
} |
6 changes: 6 additions & 0 deletions
6
cpp/ql/test/library-tests/exprs/implicitly_declared/implicit.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// semmle-extractor-options: --expect_errors | ||
|
||
void f() { | ||
f(); | ||
g(); | ||
} |
1 change: 1 addition & 0 deletions
1
cpp/ql/test/library-tests/exprs/implicitly_declared/implicit.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| implicit.c:3:5:3:5 | call to g | |
5 changes: 5 additions & 0 deletions
5
cpp/ql/test/library-tests/exprs/implicitly_declared/implicit.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import cpp | ||
|
||
from Call c | ||
where c.mayBeFromImplicitlyDeclaredFunction() | ||
select c |
1 change: 1 addition & 0 deletions
1
cpp/ql/test/library-tests/exprs/implicitly_declared/implicit2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
float g(); |
1 change: 1 addition & 0 deletions
1
...s/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/WrongTypeFormatArguments.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. | |
1 change: 1 addition & 0 deletions
1
...ests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/WrongTypeFormatArguments.qlref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Likely Bugs/Format/WrongTypeFormatArguments.ql |
11 changes: 11 additions & 0 deletions
11
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/tests.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// semmle-extractor-options: --expect_errors | ||
|
||
int printf(const char * format, ...); | ||
int fprintf(); | ||
|
||
void f() { | ||
printf("%s", 1); // BAD | ||
printf("%s", implicit_function()); // GOOD - we should ignore the type | ||
sprintf(0, "%s", ""); // GOOD | ||
fprintf(0, "%s", ""); // GOOD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters