From e90bb24a379b4cb2c467eda4fcdc369c0fefd140 Mon Sep 17 00:00:00 2001 From: h00514358 Date: Thu, 25 Aug 2022 21:23:15 +0800 Subject: [PATCH 1/4] Modify warning Signed-off-by: h00514358 Change-Id: Id165f525ca690f9d3ac3041c86ad8d3b9a564105 --- 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 cc02e211c92288738e33c9dd728741bb16f7849d Mon Sep 17 00:00:00 2001 From: h00514358 Date: Fri, 26 Aug 2022 09:30:04 +0800 Subject: [PATCH 2/4] Modify warning Signed-off-by: h00514358 Change-Id: I68cd30327dd2c8c75ab7950ff4371ffe7e9372d7 --- 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 84d39287a6fc83bf02abef0e003cb7635dc70e43 Mon Sep 17 00:00:00 2001 From: h00514358 Date: Sat, 27 Aug 2022 16:44:43 +0800 Subject: [PATCH 3/4] Modify warning Signed-off-by: h00514358 Change-Id: Ie7a8de5b540e81509b54f0d5d9264bd171a558da --- 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 8056fa5dfd8e2b2c5be4fecbef57af10070951fa Mon Sep 17 00:00:00 2001 From: h00514358 Date: Sat, 27 Aug 2022 17:22:51 +0800 Subject: [PATCH 4/4] Modify warning Signed-off-by: h00514358 Change-Id: I669a467d46a9b1d32ec8681f8bf0a338f47676e9 --- 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