]> git.saurik.com Git - wxWidgets.git/commitdiff
don't pass 0 time_t to Borland localtime(), it crashes (bug 1704438); also check...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 22 Apr 2007 00:03:16 +0000 (00:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 22 Apr 2007 00:03:16 +0000 (00:03 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45573 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/datetime.cpp

index f69eeb9e92fa3545fa5872b604c27cab70f943f8..765e3164192d7fc4adcdda191632be7c24efa5ea 100644 (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;
 }