Skip to content

Commit cff3f9b

Browse files
committed
CPP: Add another test case based on a real world case.
1 parent b1f6294 commit cff3f9b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
| 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 |
22
| 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 |
3+
| test.cpp:193:15:193:18 | days | 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:15:193:18 | days | days | test.cpp:193:15:193:18 | days | days |
4+
| test.cpp:193:15: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:15:193:24 | ... / ... | ... / ... | test.cpp:193:15:193:24 | ... / ... | ... / ... |
5+
| test.cpp:193:22:193:24 | 365 | 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:22:193:24 | 365 | 365 | test.cpp:193:22:193:24 | 365 | 365 |

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+
}

0 commit comments

Comments
 (0)