Skip to content

Commit de65dc5

Browse files
authored
Merge pull request #1490 from geoffw0/leapyeararith
CPP: Improvements to LeapYear.qll
2 parents 0fa41f7 + 5621417 commit de65dc5

16 files changed

+196
-136
lines changed

cpp/ql/src/Likely Bugs/Leap Year/Adding365daysPerYear.qhelp renamed to cpp/ql/src/Likely Bugs/Leap Year/Adding365DaysPerYear.qhelp

File renamed without changes.

cpp/ql/src/Likely Bugs/Leap Year/Adding365daysPerYear.ql renamed to cpp/ql/src/Likely Bugs/Leap Year/Adding365DaysPerYear.ql

File renamed without changes.

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

Lines changed: 147 additions & 133 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| 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 | ... = ... | ... = ... |
2+
| 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 | ... = ... | ... = ... |
3+
| 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 | ... = ... | ... = ... |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Leap Year/Adding365DaysPerYear.ql

cpp/ql/test/query-tests/Likely Bugs/Leap Year/AntiPattern2/test.cpp renamed to cpp/ql/test/query-tests/Likely Bugs/Leap Year/Adding365DaysPerYear/test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,24 @@ void antipattern2()
176176
// convert back to SYSTEMTIME for display or other usage
177177
FileTimeToSystemTime(&ft, &st);
178178
}
179+
180+
time_t mktime(struct tm *timeptr);
181+
struct tm *gmtime(const time_t *timer);
182+
183+
time_t mkTime(int days)
184+
{
185+
struct tm tm;
186+
time_t t;
187+
188+
tm.tm_sec = 0;
189+
tm.tm_min = 0;
190+
tm.tm_hour = 0;
191+
tm.tm_mday = 0;
192+
tm.tm_mon = 0;
193+
tm.tm_year = days / 365; // BAD
194+
// ...
195+
196+
t = mktime(&tm); // convert tm -> time_t
197+
198+
return t;
199+
}

cpp/ql/test/query-tests/Likely Bugs/Leap Year/AntiPattern2/Adding365daysPerYear.expected

Lines changed: 0 additions & 2 deletions
This file was deleted.

cpp/ql/test/query-tests/Likely Bugs/Leap Year/AntiPattern2/Adding365daysPerYear.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/ql/test/query-tests/Likely Bugs/Leap Year/AntiPattern1/UncheckedLeapYearAfterYearModification.expected renamed to cpp/ql/test/query-tests/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification/UncheckedLeapYearAfterYearModification.expected

File renamed without changes.

cpp/ql/test/query-tests/Likely Bugs/Leap Year/AntiPattern1/UncheckedLeapYearAfterYearModification.qlref renamed to cpp/ql/test/query-tests/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification/UncheckedLeapYearAfterYearModification.qlref

File renamed without changes.

0 commit comments

Comments
 (0)