Skip to content

Commit ba3bf2b

Browse files
committed
IntgerOverflow: Expose getting a valid post check.
1 parent 3a33a22 commit ba3bf2b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cpp/common/src/codingstandards/cpp/Overflow.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,26 @@ class InterestingOverflowingOperation extends Operation {
193193
*
194194
* Only holds for unsigned expressions, as signed overflow/underflow are undefined behavior.
195195
*/
196-
predicate hasValidPostCheck() {
196+
predicate hasValidPostCheck() { exists(getAValidPostCheck()) }
197+
198+
/**
199+
* Gets a correct validity check, `gc`, after this expression which may overflow.
200+
*/
201+
GuardCondition getAValidPostCheck() {
197202
this.getType().(IntegralType).isUnsigned() and
198203
(
199204
exists(RelationalOperation ro |
200205
DataFlow::localExprFlow(this, ro.getLesserOperand()) and
201206
globalValueNumber(ro.getGreaterOperand()) = globalValueNumber(this.getAnOperand()) and
202207
(this instanceof AddExpr or this instanceof AssignAddExpr) and
203-
ro instanceof GuardCondition
208+
result = ro
204209
)
205210
or
206211
exists(RelationalOperation ro |
207212
DataFlow::localExprFlow(this, ro.getGreaterOperand()) and
208213
globalValueNumber(ro.getLesserOperand()) = globalValueNumber(this.getAnOperand()) and
209214
(this instanceof SubExpr or this instanceof AssignSubExpr) and
210-
ro instanceof GuardCondition
215+
result = ro
211216
)
212217
)
213218
}

0 commit comments

Comments
 (0)