C++: Use the unary version of 'comparesEq' to handle both disjuncts.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-06-25 09:30:53 +01:00
parent d2a00fa773
commit bb8b0d0bf5

View File

@@ -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