File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -26,25 +26,25 @@ Code analysis name: `LEAP_YEAR_INVALID_DATE_KEYED_LOOKUP`
2626The following code creates a lookup table for the day of the year, assuming 365 days per year. However, this doesn't work if the year is a leap year:
2727
2828``` cpp
29- #include < vector>
30-
31- void foo (int year)
32- {
33- const std::vector<int > items(365); // C6393
34- // Initialize items and use it...
29+ #include < vector>
30+
31+ void foo (int year)
32+ {
33+ const std::vector<int > items(365); // C6393
34+ // Initialize items and use it...
3535}
3636```
3737
3838To fix the problem, adjust the size of the lookup table as the table is created according to the result of appropriate leap year check:
3939
4040```cpp
41- #include <vector>
42-
43- void foo(int year)
44- {
45- bool isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
46- const std::vector<int> items(isLeapYear ? 366 : 365);
47- // Initialize items and use it...
41+ #include <vector>
42+
43+ void foo(int year)
44+ {
45+ bool isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
46+ const std::vector<int> items(isLeapYear ? 366 : 365);
47+ // Initialize items and use it...
4848}
4949```
5050
You can’t perform that action at this time.
0 commit comments