зеркало из https://github.com/github/codeql.git
Merge pull request #15998 from MathiasVP/simplify-guard-in-incorrectly-check-scanf
C++: Simplify use of guard conditions in `cpp/incorrectly-checked-scanf`
This commit is contained in:
Коммит
06313b9bb6
|
@ -3,10 +3,6 @@ private import semmle.code.cpp.commons.Scanf
|
||||||
private import semmle.code.cpp.controlflow.IRGuards
|
private import semmle.code.cpp.controlflow.IRGuards
|
||||||
private import semmle.code.cpp.ir.ValueNumbering
|
private import semmle.code.cpp.ir.ValueNumbering
|
||||||
|
|
||||||
private ConstantInstruction getZeroInstruction() { result.getValue() = "0" }
|
|
||||||
|
|
||||||
private Operand zero() { result.getDef() = getZeroInstruction() }
|
|
||||||
|
|
||||||
private predicate exprInBooleanContext(Expr e) {
|
private predicate exprInBooleanContext(Expr e) {
|
||||||
exists(IRGuardCondition gc |
|
exists(IRGuardCondition gc |
|
||||||
exists(Instruction i |
|
exists(Instruction i |
|
||||||
|
@ -46,7 +42,7 @@ private predicate checkedForEof(ScanfFunctionCall call) {
|
||||||
gc.comparesEq(valueNumber(i).getAUse(), getEofValue().toInt(), _, _)
|
gc.comparesEq(valueNumber(i).getAUse(), getEofValue().toInt(), _, _)
|
||||||
or
|
or
|
||||||
// call < 0 (EOF is guaranteed to be negative)
|
// call < 0 (EOF is guaranteed to be negative)
|
||||||
gc.comparesLt(valueNumber(i).getAUse(), zero(), 0, true, _)
|
gc.comparesLt(valueNumber(i).getAUse(), 0, true, _)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче