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

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
C++: simplify cpp/guarded-free
This new form is more declarative by use of the `GuardCondition`. Thanks to the tireless effort of @MathiasVP!
  • Loading branch information
mario-campos committed May 1, 2024
commit c480431ec0aa5f67fcb472b8a58430f012090795
33 changes: 5 additions & 28 deletions cpp/ql/src/experimental/Best Practices/GuardedFree.ql
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,9 @@ class FreeCall extends FunctionCall {
FreeCall() { this.getTarget().hasGlobalName("free") }
}

from IfStmt stmt, FreeCall fc, Variable v
from GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb
where
stmt.getThen() = fc.getEnclosingStmt() and
(
stmt.getCondition() = v.getAnAccess() and
fc.getArgument(0) = v.getAnAccess()
or
exists(PointerDereferenceExpr cond, PointerDereferenceExpr arg |
fc.getArgument(0) = arg and
stmt.getCondition() = cond and
cond.getOperand+() = v.getAnAccess() and
arg.getOperand+() = v.getAnAccess()
)
or
exists(ArrayExpr cond, ArrayExpr arg |
fc.getArgument(0) = arg and
stmt.getCondition() = cond and
cond.getArrayBase+() = v.getAnAccess() and
arg.getArrayBase+() = v.getAnAccess()
)
or
exists(NEExpr eq |
fc.getArgument(0) = v.getAnAccess() and
stmt.getCondition() = eq and
eq.getAnOperand() = v.getAnAccess() and
eq.getAnOperand().getValue() = "0"
)
)
select stmt, "unnecessary NULL check before call to $@", fc, "free"
gc.ensuresEq(v.getAnAccess(), 0, bb, false) and
fc.getArgument(0) = v.getAnAccess() and
bb = fc.getEnclosingStmt()
select gc, "unnecessary NULL check before call to $@", fc, "free"