From 2658ced70b418aea0b2a6cd3e942170c83ad2b08 Mon Sep 17 00:00:00 2001 From: ilho kim Date: Thu, 3 Aug 2023 11:32:40 +0900 Subject: [PATCH] Fix static analysis issue '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 --- src/common/step/configuration/step_parse_manifest.cc | 6 ++---- src/common/utils/time_util.cc | 17 +++++++++++++++++ src/common/utils/time_util.h | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/common/utils/time_util.cc create mode 100644 src/common/utils/time_util.h diff --git a/src/common/step/configuration/step_parse_manifest.cc b/src/common/step/configuration/step_parse_manifest.cc index 186b548..2caedf2 100644 --- a/src/common/step/configuration/step_parse_manifest.cc +++ b/src/common/step/configuration/step_parse_manifest.cc @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -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 index 0000000..e318e02 --- /dev/null +++ b/src/common/utils/time_util.cc @@ -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 +#include + +namespace common_installer { + +std::string GetCurrentTime() { + return std::to_string(std::chrono::duration_cast( + 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 index 0000000..9236bfe --- /dev/null +++ b/src/common/utils/time_util.h @@ -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 + +namespace common_installer { + +std::string GetCurrentTime(); + +} // namespace common_installer + +#endif // COMMON_UTILS_TIME_UTIL_H_ -- 2.7.4