From 55809d1394516044a90fa34b12070d0f3e9f1439 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Apr 2007 00:03:16 +0000 Subject: [PATCH] don't pass 0 time_t to Borland localtime(), it crashes (bug 1704438); also check for error return from both localtime() and gmtime() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45573 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetime.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index f69eeb9e92..765e316419 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -210,7 +210,18 @@ struct tm *wxLocaltime_r(const time_t* ticks, struct tm* temp) // thread local storage for localtime anyway. wxMutexLocker locker(timeLock); #endif - memcpy(temp, localtime(ticks), sizeof(struct tm)); + + // Borland CRT crashes when passed 0 ticks for some reason, see SF bug 1704438 +#ifdef __BORLANDC__ + if ( !*ticks ) + return NULL; +#endif + + const tm * const t = localtime(ticks); + if ( !t ) + return NULL; + + memcpy(temp, t, sizeof(struct tm)); return temp; } #endif // !HAVE_LOCALTIME_R @@ -223,6 +234,16 @@ struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp) // using thread local storage for gmtime anyway. wxMutexLocker locker(timeLock); #endif + +#ifdef __BORLANDC__ + if ( !*ticks ) + return NULL; +#endif + + const tm * const t = gmtime(ticks); + if ( !t ) + return NULL; + memcpy(temp, gmtime(ticks), sizeof(struct tm)); return temp; }