Skip to content

Commit 81fa6fc

Browse files
authored
Merge pull request #155 from microsoft/brodes/open_source_query_transition
Brodes/open source query transition
2 parents 25a46a8 + 350742a commit 81fa6fc

File tree

87 files changed

+3374
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3374
-290
lines changed

cpp/ql/src/Likely Bugs/Leap Year/Adding365DaysPerYear.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It is not safe to assume that a year is 365 days long.</p>
1111

1212
<recommendation>
1313
<p>Determine whether the time span in question contains a leap day, then perform the calculation using the correct number
14-
of days. Alternatively, use an established library routine that already contains correct leap year logic.</p>
14+
of days. Alternatively, use an established library routine that already contains correct leap year logic.</p>
1515
</recommendation>
1616

1717
<references>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* value of 365, it may be a sign that leap years are not taken
55
* into account.
66
* @kind problem
7-
* @problem.severity warning
7+
* @problem.severity error
88
* @id cpp/leap-year/adding-365-days-per-year
99
* @precision medium
1010
* @tags leap-year
@@ -13,11 +13,13 @@
1313

1414
import cpp
1515
import LeapYear
16+
import semmle.code.cpp.dataflow.new.DataFlow
1617

1718
from Expr source, Expr sink
1819
where
1920
PossibleYearArithmeticOperationCheckFlow::flow(DataFlow::exprNode(source),
2021
DataFlow::exprNode(sink))
2122
select sink,
22-
"An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios.",
23-
source, source.toString()
23+
"$@: This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios.",
24+
sink.getEnclosingFunction(), sink.getEnclosingFunction().toString(), source, source.toString(),
25+
sink, sink.toString()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Leap Year Invalid Check (AntiPattern 5)
3+
* @description An expression is used to check a year is presumably a leap year, but the conditions used are insufficient.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id cpp/leap-year/invalid-leap-year-check
7+
* @precision medium
8+
* @tags leap-year
9+
* correctness
10+
*/
11+
12+
import cpp
13+
import LeapYear
14+
15+
from Mod4CheckedExpr exprMod4
16+
where not exists(ExprCheckLeapYear lyCheck | lyCheck.getAChild*() = exprMod4)
17+
select exprMod4, "Possible Insufficient Leap Year check (AntiPattern 5)"

0 commit comments

Comments
 (0)