mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
C++: Use the unary version of 'comparesEq' to handle both disjuncts.
This commit is contained in:
@@ -215,13 +215,18 @@ predicate noThrowInTryBlock(NewOrNewArrayExpr newExpr, BadAllocCatchBlock catchB
|
|||||||
*/
|
*/
|
||||||
predicate nullCheckInThrowingNew(NewOrNewArrayExpr newExpr, GuardCondition guard) {
|
predicate nullCheckInThrowingNew(NewOrNewArrayExpr newExpr, GuardCondition guard) {
|
||||||
newExpr.getAllocator() instanceof ThrowingAllocator and
|
newExpr.getAllocator() instanceof ThrowingAllocator and
|
||||||
(
|
// There can be many guard conditions that compares `newExpr` againgst 0.
|
||||||
// Handles null comparisons.
|
// For example, for `if(!p)` both `p` and `!p` is a guard condition. To not
|
||||||
guard.ensuresEq(globalValueNumber(newExpr).getAnExpr(), any(NullValue null), _, _, _)
|
// produce duplicates results we pick the "first" guard condition according
|
||||||
or
|
// to some arbitrary ordering (i.e., location information). This means `!p` is the
|
||||||
// Handles `if(ptr)` and `if(!ptr)` cases.
|
// element that we use to construct the alert.
|
||||||
guard = globalValueNumber(newExpr).getAnExpr()
|
guard =
|
||||||
)
|
min(GuardCondition gc, int startline, int startcolumn, int endline, int endcolumn |
|
||||||
|
gc.comparesEq(globalValueNumber(newExpr).getAnExpr(), 0, _, _) and
|
||||||
|
gc.getLocation().hasLocationInfo(_, startline, startcolumn, endline, endcolumn)
|
||||||
|
|
|
||||||
|
gc order by startline, startcolumn, endline, endcolumn
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
from NewOrNewArrayExpr newExpr, Element element, string msg, string elementString
|
from NewOrNewArrayExpr newExpr, Element element, string msg, string elementString
|
||||||
|
|||||||
Reference in New Issue
Block a user