Skip to content

Commit b1f6294

Browse files
committed
CPP: Add a test case where a date is created.
1 parent 09b33bc commit b1f6294

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
| test.cpp:636:11:636:17 | tm_year | Field $@ on variable $@ has been modified, but no appropriate check for LeapYear was found. | test.cpp:56:6:56:12 | tm_year | tm_year | test.cpp:628:12:628:19 | timeinfo | timeinfo |
1010
| test.cpp:640:5:640:9 | wYear | Field $@ on variable $@ has been modified, but no appropriate check for LeapYear was found. | test.cpp:12:7:12:11 | wYear | wYear | test.cpp:629:13:629:14 | st | st |
1111
| test.cpp:642:5:642:9 | wYear | Field $@ on variable $@ has been modified, but no appropriate check for LeapYear was found. | test.cpp:12:7:12:11 | wYear | wYear | test.cpp:629:13:629:14 | st | st |
12+
| test.cpp:677:5:677:11 | tm_year | Field $@ on variable $@ has been modified, but no appropriate check for LeapYear was found. | test.cpp:56:6:56:12 | tm_year | tm_year | test.cpp:664:12:664:12 | t | t |

cpp/ql/test/query-tests/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification/test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,27 @@ IncrementMonth(LPSYSTEMTIME pst)
656656
pst->wYear++;
657657
}
658658
}
659+
660+
/////////////////////////////////////////////////////////
661+
662+
void mkDateTest(int year)
663+
{
664+
struct tm t;
665+
666+
t.tm_sec = 0;
667+
t.tm_min = 0;
668+
t.tm_hour = 0;
669+
t.tm_mday = 1; // day of the month - [1, 31]
670+
t.tm_mon = 0; // months since January - [0, 11]
671+
if (year >= 1900)
672+
{
673+
// 4-digit year
674+
t.tm_year = year - 1900; // GOOD
675+
} else if ((year >= 0) && (year < 100)) {
676+
// 2-digit year assumed in the range 2000 - 2099
677+
t.tm_year = year + 100; // GOOD [FALSE POSITIVE]
678+
} else {
679+
// fail
680+
}
681+
// ...
682+
}

0 commit comments

Comments
 (0)