Skip to content

Commit 6a05c84

Browse files
authored
Merge pull request #3 from geoffw0/dates-fix
CPP: Fixes for C++: Mishandling Japanese Era and Leap Year in calculations #1354
2 parents 7ff8fcd + 8ebc0b9 commit 6a05c84

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<include src="LeapYear.qhelp" />
7+
8+
<p>When performing arithmetic operations on a variable that represents a date, leap years must be taken into account.
9+
It is not safe to assume that a year is 365 days long.</p>
10+
</overview>
11+
12+
<recommendation>
13+
<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>
15+
</recommendation>
16+
17+
<references>
18+
<include src="LeapYearReferences.qhelp" />
19+
</references>
20+
</qhelp>

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
"-//Semmle//qhelp//EN"
33
"qhelp.dtd">
44
<qhelp>
5-
<overview>
6-
<p>The leap year rule for the Gregorian calendar, which has become the internationally accepted civil calendar, is: every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.</p>
7-
<p>A leap year bug occurs when software (in any language) is written without consideration of leap year logic, or with flawed logic to calculate leap years; which typically results in incorrect results.</p>
8-
<p>The impact of these bugs may range from almost unnoticeable bugs such as an incorrect date, to severe bugs that affect reliability, availability or even the security of the affected system.</p>
9-
</overview>
10-
11-
<references>
12-
<li>U.S. Naval Observatory Website - <a href="https://aa.usno.navy.mil/faq/docs/calendars.php"> Introduction to Calendars</a></li>
13-
<li>Wikipedia - <a href="https://en.wikipedia.org/wiki/Leap_year_bug"> Leap year bug</a> </li>
14-
<li>Microsoft Azure blog - <a href="https://azure.microsoft.com/en-us/blog/is-your-code-ready-for-the-leap-year/"> Is your code ready for the leap year?</a> </li>
15-
</references>
5+
<fragment>
6+
<p>The leap year rule for the Gregorian calendar, which has become the internationally accepted civil calendar, is: every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.</p>
7+
<p>A leap year bug occurs when software (in any language) is written without consideration of leap year logic, or with flawed logic to calculate leap years; which typically results in incorrect results.</p>
8+
<p>The impact of these bugs may range from almost unnoticeable bugs such as an incorrect date, to severe bugs that affect reliability, availability or even the security of the affected system.</p>
9+
</fragment>
1610
</qhelp>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<fragment>
6+
<li>U.S. Naval Observatory Website - <a href="https://aa.usno.navy.mil/faq/docs/calendars.php"> Introduction to Calendars</a></li>
7+
<li>Wikipedia - <a href="https://en.wikipedia.org/wiki/Leap_year_bug"> Leap year bug</a> </li>
8+
<li>Microsoft Azure blog - <a href="https://azure.microsoft.com/en-us/blog/is-your-code-ready-for-the-leap-year/"> Is your code ready for the leap year?</a> </li>
9+
</fragment>
10+
</qhelp>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@
2121
<sample src="UncheckedLeapYearAfterYearModificationGood.c" />
2222
</example>
2323

24+
<references>
25+
<include src="LeapYearReferences.qhelp" />
26+
</references>
2427
</qhelp>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@
3333
<sample src="UncheckedLeapYearAfterYearModificationGood.c" />
3434
</example>
3535

36+
<references>
37+
<include src="LeapYearReferences.qhelp" />
38+
</references>
3639
</qhelp>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
<sample src="UnsafeArrayForDaysOfYearGood.c" />
2323
</example>
2424

25+
<references>
26+
<include src="LeapYearReferences.qhelp" />
27+
</references>
2528
</qhelp>

0 commit comments

Comments
 (0)