selcommands: fix the exception when parsing SEL timestamp

(1) Fix the problem caused by casting to mismatched size that time_t
is 8 bytes.
(2) Change to use thread-safe APIs to covert the timestamp.

Change-Id: Iac86f636b049ff82bb0df2410afb860436dc882c
Signed-off-by: Cosmo Chou <cosmo.chou@quantatw.com>
diff --git a/src/selcommands.cpp b/src/selcommands.cpp
index 3572269..420c797 100644
--- a/src/selcommands.cpp
+++ b/src/selcommands.cpp
@@ -1186,9 +1186,17 @@
             }
         }
 
-        uint32_t timeStamp = data->timeStamp;
-        std::tm* ts = localtime(reinterpret_cast<time_t*>(&timeStamp));
-        std::string timeStr = std::asctime(ts);
+        time_t timeStamp = static_cast<time_t>(data->timeStamp);
+        std::string timeStr;
+        std::tm ts;
+        if (localtime_r(&timeStamp, &ts))
+        {
+            char buf[64];
+            if (strftime(buf, sizeof(buf), "%c", &ts))
+            {
+                timeStr = buf;
+            }
+        }
 
         parseStdSel(data, errLog);
         ptr = &(data->eventData1);
@@ -1219,9 +1227,17 @@
         std::string oemDataStr;
         toHexStr(oemData, oemDataStr);
 
-        uint32_t timeStamp = data->timeStamp;
-        std::tm* ts = localtime(reinterpret_cast<time_t*>(&timeStamp));
-        std::string timeStr = std::asctime(ts);
+        time_t timeStamp = static_cast<time_t>(data->timeStamp);
+        std::string timeStr;
+        std::tm ts;
+        if (localtime_r(&timeStamp, &ts))
+        {
+            char buf[64];
+            if (strftime(buf, sizeof(buf), "%c", &ts))
+            {
+                timeStr = buf;
+            }
+        }
 
         errType = oemTSErr;
         parseOemSel(data, errLog);