Replace localtime() with thread safe localtime_r()
[libi2ncommon] / src / timefunc.cpp
index a45f00e..ab5f6dc 100644 (file)
@@ -133,9 +133,11 @@ string format_full_time(int seconds)
 {
     char buf[50];
     memset (buf, 0, 50);
-    struct tm *ta = localtime ((time_t *)&seconds);
+    struct tm ta;
+    if (localtime_r((time_t *)&seconds, &ta) == NULL)
+        memset (&ta, 0, sizeof(struct tm));
 
-    strftime (buf, 49, "%d.%m.%Y %H:%M", ta);
+    strftime (buf, 49, "%d.%m.%Y %H:%M", &ta);
     return string(buf);
 }