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
This commit is contained in:
Vadim Zeitlin 2007-04-22 00:03:16 +00:00
parent a930afc71b
commit 55809d1394

View File

@ -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;
}