Fix static analysis issue 67/296667/3
authorilho kim <ilho159.kim@samsung.com>
Thu, 3 Aug 2023 02:32:40 +0000 (11:32 +0900)
committerilho kim <ilho159.kim@samsung.com>
Thu, 3 Aug 2023 06:15:59 +0000 (15:15 +0900)
'std::time_t' to 'long' may or may not override sign-bit depending on
size of implementation defined type
which may cause unexpected results on porting to different platforms

Change-Id: I58da7b195c5215617fdad5264cd91216c8ca8700
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/common/step/configuration/step_parse_manifest.cc
src/common/utils/time_util.cc [new file with mode: 0644]
src/common/utils/time_util.h [new file with mode: 0644]

index 186b548..2caedf2 100644 (file)
@@ -28,7 +28,6 @@
 #include <tpk_manifest_handlers/watch_application_handler.h>
 #include <tpk_manifest_handlers/widget_application_handler.h>
 
-#include <chrono>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -46,6 +45,7 @@
 #include "common/utils/pkgmgr_query.h"
 #include "common/step/step.h"
 #include "common/utils/glist_range.h"
+#include "common/utils/time_util.h"
 
 namespace app_keys = tpk::application_keys;
 namespace bf = boost::filesystem;
@@ -188,9 +188,7 @@ int StepParseManifest::GetSupportModeVal(std::string support_mode) {
 bool StepParseManifest::FillInstallationInfo(manifest_x* manifest) {
   manifest->root_path = strdup(
       (context_->root_application_path.get() / manifest->package).c_str());
-  manifest->installed_time =
-      strdup(std::to_string(std::chrono::system_clock::to_time_t(
-          std::chrono::system_clock::now())).c_str());
+  manifest->installed_time = strdup(GetCurrentTime().c_str());
   return true;
 }
 
diff --git a/src/common/utils/time_util.cc b/src/common/utils/time_util.cc
new file mode 100644 (file)
index 0000000..e318e02
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/utils/time_util.h"
+
+#include <chrono>
+#include <string>
+
+namespace common_installer {
+
+std::string GetCurrentTime() {
+  return std::to_string(std::chrono::duration_cast<std::chrono::seconds>(
+      std::chrono::system_clock::now().time_since_epoch()).count());
+}
+
+}  // namespace common_installer
diff --git a/src/common/utils/time_util.h b/src/common/utils/time_util.h
new file mode 100644 (file)
index 0000000..9236bfe
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_UTILS_TIME_UTIL_H_
+#define COMMON_UTILS_TIME_UTIL_H_
+
+#include <string>
+
+namespace common_installer {
+
+std::string GetCurrentTime();
+
+}  // namespace common_installer
+
+#endif  // COMMON_UTILS_TIME_UTIL_H_