From 4d2275202af6d1ed3c72906bd5d1f91179bf6802 Mon Sep 17 00:00:00 2001 From: HYH Date: Thu, 25 Aug 2022 13:30:01 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HYH --- test/unittest/common/src/system_info.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index d0f5d648..a2cc7b73 100755 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -23,6 +23,7 @@ #include #include +#include "securec.h" #include "sensors_errors.h" namespace OHOS { @@ -75,7 +76,7 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) } while (std::getline(filePath, strLine)) { if ((strLine.find("Pid")) != std::string::npos) { - (void)::sscanf(strLine.c_str(), "%*s%d", &pid); + (void)::sscanf_s(strLine.c_str(), "%*s%d", &pid); break; } } -- Gitee From 1e6a43551f23e5d9601001342732ca6fc231a593 Mon Sep 17 00:00:00 2001 From: HYH Date: Fri, 26 Aug 2022 01:31:29 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HYH --- test/unittest/common/src/system_info.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index a2cc7b73..0a39c368 100755 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -76,7 +76,9 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) } while (std::getline(filePath, strLine)) { if ((strLine.find("Pid")) != std::string::npos) { - (void)::sscanf_s(strLine.c_str(), "%*s%d", &pid); + if (sscanf_s(strLine.c_str(), "%*s%d", &pid) != 1) { + SEN_HILOGE("sscanf_s failed"); + } break; } } -- Gitee From 7eb7b50bcffa5a0a26b6bc97f8ec48312c214fba Mon Sep 17 00:00:00 2001 From: HYH Date: Sat, 27 Aug 2022 08:49:02 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HYH --- test/unittest/common/src/system_info.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index 0a39c368..0a89e6a1 100755 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -35,6 +35,7 @@ constexpr HiLogLabel LABEL = { LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SYST constexpr int32_t LOCATION = 14; constexpr int32_t TIME_WAIT_FOR_OP = 1000; constexpr int32_t DEFAULT_PID = -1; +constexpr int32_t ERROR_CODE = -1; } // namespace inline double CHK_RATE(double rate) @@ -76,7 +77,7 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) } while (std::getline(filePath, strLine)) { if ((strLine.find("Pid")) != std::string::npos) { - if (sscanf_s(strLine.c_str(), "%*s%d", &pid) != 1) { + if (sscanf_s(strLine.c_str(), "%*s%d", &pid) == ERROR_CODE) { SEN_HILOGE("sscanf_s failed"); } break; -- Gitee From abde620724db665d2b2e89e26590f79efcb2b675 Mon Sep 17 00:00:00 2001 From: HYH Date: Sat, 27 Aug 2022 09:23:39 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HYH --- test/unittest/common/src/system_info.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index 0a89e6a1..f21a27cc 100755 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -35,7 +35,6 @@ constexpr HiLogLabel LABEL = { LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SYST constexpr int32_t LOCATION = 14; constexpr int32_t TIME_WAIT_FOR_OP = 1000; constexpr int32_t DEFAULT_PID = -1; -constexpr int32_t ERROR_CODE = -1; } // namespace inline double CHK_RATE(double rate) @@ -77,7 +76,7 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) } while (std::getline(filePath, strLine)) { if ((strLine.find("Pid")) != std::string::npos) { - if (sscanf_s(strLine.c_str(), "%*s%d", &pid) == ERROR_CODE) { + if (sscanf_s(strLine.c_str(), "%*s%d", &pid) == -1) { SEN_HILOGE("sscanf_s failed"); } break; -- Gitee