Skip to content

Commit 2ced9d8

Browse files
authored
Merge pull request #162 from marcgurevitx/fix-dateStr-bignums
Fix date str bignums
2 parents daabb9a + f4a13e0 commit 2ced9d8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

MiniScript-cpp/src/DateTimeUtils.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
#if _WIN32 || _WIN64
1515
struct tm *localtime_r( const time_t *timer, struct tm *buf ) {
16-
*buf = *_localtime64(timer);
16+
struct tm *newtime = _localtime64(timer);
17+
if (newtime == nullptr) return nullptr;
18+
*buf = *newtime;
1719
return buf;
1820
}
1921
#endif
@@ -31,7 +33,8 @@ static bool Match(const String s, size_t *posB, const String match) {
3133

3234
String FormatDate(time_t t, String formatSpec) {
3335
tm dateTime;
34-
localtime_r(&t, &dateTime);
36+
struct tm *newtime = localtime_r(&t, &dateTime);
37+
if (newtime == nullptr) return ""; // arg t too large
3538

3639
const int BUFSIZE = 128;
3740
char buffer[BUFSIZE];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import "qa"
2+
3+
testDateTimeDateStr = function
4+
qa.assertEqual _dateStr(0), "2000-01-01 00:00:00"
5+
qa.assertEqual _dateStr(1e20), ""
6+
end function
7+
8+
if refEquals(locals, globals) then testDateTimeDateStr

0 commit comments

Comments
 (0)