Merge pull request #1490 from geoffw0/leapyeararith

CPP: Improvements to LeapYear.qll
This commit is contained in:
Jonas Jensen
2019-06-25 10:46:12 +02:00
committed by GitHub
16 changed files with 197 additions and 137 deletions

View File

@@ -0,0 +1,3 @@
| 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 | ... = ... | ... = ... |
| 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 | ... = ... | ... = ... |
| 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 | ... = ... | ... = ... |

View File

@@ -0,0 +1 @@
Likely Bugs/Leap Year/Adding365DaysPerYear.ql

View File

@@ -176,3 +176,24 @@ void antipattern2()
// convert back to SYSTEMTIME for display or other usage
FileTimeToSystemTime(&ft, &st);
}
time_t mktime(struct tm *timeptr);
struct tm *gmtime(const time_t *timer);
time_t mkTime(int days)
{
struct tm tm;
time_t t;
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 0;
tm.tm_mday = 0;
tm.tm_mon = 0;
tm.tm_year = days / 365; // BAD
// ...
t = mktime(&tm); // convert tm -> time_t
return t;
}

View File

@@ -1,2 +0,0 @@
| 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 |
| 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 |

View File

@@ -1 +0,0 @@
Likely Bugs/Leap Year/Adding365daysPerYear.ql

View File

@@ -656,3 +656,27 @@ IncrementMonth(LPSYSTEMTIME pst)
pst->wYear++;
}
}
/////////////////////////////////////////////////////////
void mkDateTest(int year)
{
struct tm t;
t.tm_sec = 0;
t.tm_min = 0;
t.tm_hour = 0;
t.tm_mday = 1; // day of the month - [1, 31]
t.tm_mon = 0; // months since January - [0, 11]
if (year >= 1900)
{
// 4-digit year
t.tm_year = year - 1900; // GOOD
} else if ((year >= 0) && (year < 100)) {
// 2-digit year assumed in the range 2000 - 2099
t.tm_year = year + 100; // GOOD [FALSE POSITIVE]
} else {
// fail
}
// ...
}