Skip to content

Commit 69533a7

Browse files
committed
CPP: Clean up duplication in Adding365DaysPerYear.ql.
1 parent 7fca220 commit 69533a7

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,33 @@ class PossibleYearArithmeticOperationCheckConfiguration extends DataFlow::Config
258258
}
259259

260260
override predicate isSource(DataFlow::Node source) {
261-
exists( Expr e, Operation op |
262-
e = source.asExpr() |
263-
op.getAChild*().getValue().toInt()=365
264-
and op.getAChild*() = e
265-
)
261+
exists(Operation op |
262+
op = source.asExpr() |
263+
op.getAChild*().getValue().toInt() = 365 and
264+
not op.getParent() instanceof Expr
265+
)
266266
}
267-
267+
268+
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
269+
// flow from anything on the RHS of an assignment to a time/date structure to that
270+
// assignment.
271+
exists(StructLikeClass dds, FieldAccess fa, AssignExpr aexpr, Expr e |
272+
e = node1.asExpr() and
273+
aexpr = node2.asExpr() |
274+
(dds instanceof FileTimeStruct or dds instanceof DateDataStruct)
275+
and fa.getQualifier().getUnderlyingType() = dds
276+
and aexpr.getLValue() = fa
277+
and aexpr.getRValue().getAChild*() = e
278+
)
279+
}
280+
268281
override predicate isSink(DataFlow::Node sink) {
269-
exists( StructLikeClass dds, FieldAccess fa, AssignExpr aexpr, Expr e |
270-
e = sink.asExpr() |
271-
(dds instanceof FileTimeStruct
272-
or dds instanceof DateDataStruct)
273-
and fa.getQualifier().getUnderlyingType() = dds
274-
and fa.isModified()
275-
and aexpr.getAChild() = fa
276-
and aexpr.getChild(1).getAChild*() = e
282+
exists(StructLikeClass dds, FieldAccess fa, AssignExpr aexpr |
283+
aexpr = sink.asExpr() |
284+
(dds instanceof FileTimeStruct or dds instanceof DateDataStruct)
285+
and fa.getQualifier().getUnderlyingType() = dds
286+
and fa.isModified()
287+
and aexpr.getLValue() = fa
277288
)
278289
}
279290
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| test.cpp:173:29:173:38 | qwLongTime | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... | test.cpp:173:29:173:38 | qwLongTime | qwLongTime |
2-
| test.cpp:174:30:174:39 | qwLongTime | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... | test.cpp:174:30:174:39 | qwLongTime | qwLongTime |
3-
| test.cpp:193:15:193:18 | days | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:15:193:18 | days | days | test.cpp:193:15:193:18 | days | days |
4-
| test.cpp:193:15:193:24 | ... / ... | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:15:193:24 | ... / ... | ... / ... | test.cpp:193:15:193:24 | ... / ... | ... / ... |
5-
| test.cpp:193:22:193:24 | 365 | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:22:193:24 | 365 | 365 | test.cpp:193:22:193:24 | 365 | 365 |
1+
| test.cpp:173:2:173:52 | ... = ... | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... | test.cpp:173:2:173:52 | ... = ... | ... = ... |
2+
| test.cpp:174:2:174:46 | ... = ... | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:170:2:170:47 | ... += ... | ... += ... | test.cpp:174:2:174:46 | ... = ... | ... = ... |
3+
| test.cpp:193:2:193:24 | ... = ... | This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios. | test.cpp:193:2:193:24 | ... = ... | ... = ... | test.cpp:193:2:193:24 | ... = ... | ... = ... |

0 commit comments

Comments
 (0)