C++: Silence ql-for-ql warning

This commit is contained in:
Jeroen Ketema
2024-11-14 13:10:20 +01:00
parent b581723a63
commit 20685918bd

View File

@@ -18,9 +18,7 @@ class FreeCall extends FunctionCall {
FreeCall() { this.getTarget().hasGlobalName("free") }
}
predicate isAffectedByMacro(FreeCall fc, BasicBlock bb) {
fc.isInMacroExpansion()
or
predicate blockContainsPreprocessorBranches(BasicBlock bb) {
exists(PreprocessorBranch ppb, Location bbLoc, Location ppbLoc |
bbLoc = bb.(Stmt).getLocation() and ppbLoc = ppb.getLocation()
|
@@ -40,7 +38,8 @@ where
strictcount(bb.(BlockStmt).getAStmt()) = 1
) and
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1 and
not isAffectedByMacro(fc, bb) and
not fc.isInMacroExpansion() and
not blockContainsPreprocessorBranches(bb) and
not (gc instanceof BinaryOperation and not gc instanceof ComparisonOperation) and
not exists(CommaExpr c | c.getAChild*() = fc)
select gc, "unnecessary NULL check before call to $@", fc, "free"