Skip to content

Commit 0ca37f2

Browse files
marcgurevitxborgi
authored andcommitted
Fix _dateStr() for large time_t values on Windows
1 parent fa0fbe0 commit 0ca37f2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

MiniScript-cpp/src/DateTimeUtils.cpp

+5-3
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,8 +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);
35-
if (errno == EOVERFLOW) return ""; // arg t too large
36+
struct tm *newtime = localtime_r(&t, &dateTime);
37+
if (errno or newtime == nullptr) return ""; // arg t too large
3638

3739
const int BUFSIZE = 128;
3840
char buffer[BUFSIZE];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "qa"
2+
3+
testDateTimeDateStr = function
4+
qa.assertEqual _dateStr(1e20), ""
5+
end function
6+
7+
if refEquals(locals, globals) then testDateTimeDateStr

0 commit comments

Comments
 (0)