mirror of
https://github.com/github/codeql.git
synced 2026-04-22 07:15:15 +02:00
C++: Also allow single statement blocks in cpp/guarded-free
This commit is contained in:
@@ -22,6 +22,11 @@ from GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb
|
||||
where
|
||||
gc.ensuresEq(v.getAnAccess(), 0, bb, false) and
|
||||
fc.getArgument(0) = v.getAnAccess() and
|
||||
bb = fc.getEnclosingStmt() and
|
||||
bb = fc.getBasicBlock() and
|
||||
(
|
||||
bb = fc.getEnclosingStmt()
|
||||
or
|
||||
strictcount(bb.(BlockStmt).getAStmt()) = 1
|
||||
) and
|
||||
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1
|
||||
select gc, "unnecessary NULL check before call to $@", fc, "free"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
| test.cpp:5:7:5:7 | x | unnecessary NULL check before call to $@ | test.cpp:6:5:6:8 | call to free | free |
|
||||
| test.cpp:10:7:10:7 | x | unnecessary NULL check before call to $@ | test.cpp:11:5:11:8 | call to free | free |
|
||||
| test.cpp:31:7:31:24 | ... \|\| ... | unnecessary NULL check before call to $@ | test.cpp:35:3:35:6 | call to free | free |
|
||||
| test.cpp:42:7:42:7 | x | unnecessary NULL check before call to $@ | test.cpp:43:5:43:8 | call to free | free |
|
||||
| test.cpp:49:7:49:7 | x | unnecessary NULL check before call to $@ | test.cpp:50:5:50:8 | call to free | free |
|
||||
| test.cpp:75:7:75:7 | x | unnecessary NULL check before call to $@ | test.cpp:76:5:76:14 | call to free | free |
|
||||
| test.cpp:81:7:81:7 | x | unnecessary NULL check before call to $@ | test.cpp:85:5:85:8 | call to free | free |
|
||||
| test.cpp:94:12:94:12 | x | unnecessary NULL check before call to $@ | test.cpp:94:3:94:13 | call to free | free |
|
||||
| test.cpp:106:7:106:18 | ... != ... | unnecessary NULL check before call to $@ | test.cpp:107:5:107:8 | call to free | free |
|
||||
| test.cpp:113:7:113:18 | ... != ... | unnecessary NULL check before call to $@ | test.cpp:114:17:114:20 | call to free | free |
|
||||
|
||||
@@ -72,13 +72,13 @@ bool test8(char *x) {
|
||||
#endif
|
||||
|
||||
void test9(char *x) {
|
||||
if (x) { // GOOD: macro may make free behave unexpectedly when compiled differently
|
||||
if (x) { // GOOD [FALSE POSITIVE]: macro may make free behave unexpectedly when compiled differently
|
||||
my_free(x);
|
||||
}
|
||||
}
|
||||
|
||||
void test10(char *x) {
|
||||
if (x) { // GOOD: #ifdef may make free behave unexpectedly when compiled differently
|
||||
if (x) { // GOOD [FALSE POSITIVE]: #ifdef may make free behave unexpectedly when compiled differently
|
||||
#ifdef FOO
|
||||
free(x - 1);
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user