Skip to content

Commit

Permalink
Fix _dateStr() for large time_t values on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgurevitx authored and borgi committed Nov 21, 2024
1 parent fa0fbe0 commit 0ca37f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions MiniScript-cpp/src/DateTimeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

#if _WIN32 || _WIN64
struct tm *localtime_r( const time_t *timer, struct tm *buf ) {
*buf = *_localtime64(timer);
struct tm *newtime = _localtime64(timer);
if (newtime == nullptr) return nullptr;
*buf = *newtime;
return buf;
}
#endif
Expand All @@ -31,8 +33,8 @@ static bool Match(const String s, size_t *posB, const String match) {

String FormatDate(time_t t, String formatSpec) {
tm dateTime;
localtime_r(&t, &dateTime);
if (errno == EOVERFLOW) return ""; // arg t too large
struct tm *newtime = localtime_r(&t, &dateTime);
if (errno or newtime == nullptr) return ""; // arg t too large

const int BUFSIZE = 128;
char buffer[BUFSIZE];
Expand Down
7 changes: 7 additions & 0 deletions MiniScript-cpp/tests/testDateTimeDateStr.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "qa"

testDateTimeDateStr = function
qa.assertEqual _dateStr(1e20), ""
end function

if refEquals(locals, globals) then testDateTimeDateStr

0 comments on commit 0ca37f2

Please sign in to comment.