Skip to content

Commit 77da7fd

Browse files
committed
Merge branch 'jb1/ap1-maturity' of https://github.com/microsoft/codeql into jb1/ap1-maturity
2 parents 09f852e + 31b9606 commit 77da7fd

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,14 @@ class StructTmLeapYearFieldAccess extends LeapYearFieldAccess {
361361
/**
362362
* `stDate.wMonth == 2`
363363
*/
364-
class DateCheckMonthFebruary extends Operation {
364+
private class DateCheckMonthFebruary extends EQExpr {
365+
MonthFieldAccess mfa;
366+
365367
DateCheckMonthFebruary() {
366-
this.getOperator() = "==" and
367-
this.getAnOperand() instanceof MonthFieldAccess and
368-
this.getAnOperand().(Literal).getValue() = "2"
368+
this.hasOperands(mfa, any(Literal lit | lit.getValue() = "2"))
369369
}
370370

371-
Expr getDateQualifier() { result = this.getAnOperand().(MonthFieldAccess).getQualifier() }
371+
Expr getDateQualifier() { result = mfa.getQualifier() }
372372
}
373373

374374
/**

cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification.ql

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ class IgnorableExpr48Mapping extends IgnorableOperation {
123123
*/
124124
class IgnorableCharLiteralArithmetic extends IgnorableOperation {
125125
IgnorableCharLiteralArithmetic() {
126-
exists(this.(BinaryArithmeticOperation).getAnOperand().(TextLiteral).getValue())
126+
this.(BinaryArithmeticOperation).getAnOperand() instanceof TextLiteral
127127
or
128-
exists(AssignArithmeticOperation e | e.getRValue() = this |
129-
exists(this.(TextLiteral).getValue())
130-
)
128+
this instanceof TextLiteral and
129+
any(AssignArithmeticOperation arith).getRValue() = this
131130
}
132131
}
133132

@@ -214,11 +213,10 @@ class OperationAsArgToIgnorableFunction extends IgnorableOperation {
214213
* and the operation is basically ignorable (it's not a real operation but
215214
* probably one visual simplicity what it means).
216215
*/
217-
class ConstantBinaryArithmeticOperation extends IgnorableOperation {
216+
class ConstantBinaryArithmeticOperation extends IgnorableOperation, BinaryArithmeticOperation {
218217
ConstantBinaryArithmeticOperation() {
219-
this instanceof BinaryArithmeticOperation and
220-
this.(BinaryArithmeticOperation).getLeftOperand() instanceof Literal and
221-
this.(BinaryArithmeticOperation).getRightOperand() instanceof Literal
218+
this.getLeftOperand() instanceof Literal and
219+
this.getRightOperand() instanceof Literal
222220
}
223221
}
224222

@@ -274,7 +272,10 @@ class IgnorablePointerOrCharArithmetic extends IgnorableOperation {
274272
*/
275273
predicate isOperationSourceCandidate(Expr e) {
276274
not e instanceof IgnorableOperation and
277-
not e.getEnclosingFunction() instanceof IgnorableFunction and
275+
exists(Function f |
276+
f = e.getEnclosingFunction() and
277+
not f instanceof IgnorableFunction
278+
)
278279
(
279280
e instanceof SubExpr
280281
or
@@ -494,7 +495,9 @@ class MonthEqualityCheck extends EqualityOperation {
494495
}
495496
}
496497

497-
class MonthEqualityCheckGuard extends GuardCondition instanceof MonthEqualityCheck { }
498+
final class FinalMonthEqualityCheck = MonthEqualityCheck;
499+
500+
class MonthEqualityCheckGuard extends GuardCondition, FinalMonthEqualityCheck { }
498501

499502
/**
500503
* Verifies if the expression is guarded by a check on the Month property of a date struct, that is NOT February.
@@ -504,7 +507,7 @@ pragma[inline_late]
504507
predicate isControlledByMonthEqualityCheckNonFebruary(Expr e) {
505508
exists(MonthEqualityCheckGuard monthGuard |
506509
monthGuard.controls(e.getBasicBlock(), true) and
507-
not monthGuard.(MonthEqualityCheck).getExprCompared().getValueText() = "2"
510+
not monthGuard.getExprCompared().getValueText() = "2"
508511
)
509512
}
510513

0 commit comments

Comments
 (0)