mirror of
https://github.com/github/codeql.git
synced 2026-02-23 02:13:41 +01:00
C++: Ignore free calls that are macro defined or #if/#ifdef guarded
This commit is contained in:
@@ -18,6 +18,17 @@ class FreeCall extends FunctionCall {
|
||||
FreeCall() { this.getTarget().hasGlobalName("free") }
|
||||
}
|
||||
|
||||
predicate isAffectedByMacro(FreeCall fc, BasicBlock bb) {
|
||||
fc.isInMacroExpansion()
|
||||
or
|
||||
exists(PreprocessorBranch ppb, Location bbLoc, Location ppbLoc |
|
||||
bbLoc = bb.(Stmt).getLocation() and ppbLoc = ppb.getLocation()
|
||||
|
|
||||
bbLoc.getStartLine() < ppbLoc.getStartLine() and
|
||||
ppbLoc.getEndLine() < bbLoc.getEndLine()
|
||||
)
|
||||
}
|
||||
|
||||
from GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb
|
||||
where
|
||||
gc.ensuresEq(v.getAnAccess(), 0, bb, false) and
|
||||
@@ -28,5 +39,6 @@ where
|
||||
or
|
||||
strictcount(bb.(BlockStmt).getAStmt()) = 1
|
||||
) and
|
||||
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1
|
||||
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1 and
|
||||
not isAffectedByMacro(fc, bb)
|
||||
select gc, "unnecessary NULL check before call to $@", fc, "free"
|
||||
|
||||
Reference in New Issue
Block a user