mirror of
https://github.com/github/codeql.git
synced 2026-05-03 20:58:03 +02:00
Merge pull request #1490 from geoffw0/leapyeararith
CPP: Improvements to LeapYear.qll
This commit is contained in:
@@ -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 | ... = ... | ... = ... |
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/Leap Year/Adding365DaysPerYear.ql
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 |
|
||||
@@ -1 +0,0 @@
|
||||
Likely Bugs/Leap Year/Adding365daysPerYear.ql
|
||||
@@ -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
|
||||
}
|
||||
// ...
|
||||
}
|
||||
Reference in New Issue
Block a user