CodeQL queries 1.24
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.
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.
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.
When performing arithmetic operations on a variable that represents a year, it is important to consider that the resulting value may not be a valid date.
The typical example is doing simple year arithmetic (i.e.
date.year++) without considering if the resulting value will be a valid date or not.
When modifying a year field on a date structure, verify if the resulting year is a leap year.
In this example, we are adding 1 year to the current date. This may work most of the time, but on any given February 29th, the resulting value will be invalid.
To fix this bug, check the result for leap year.