From 2c217cd02df850da00de0593102d65f13e529dd1 Mon Sep 17 00:00:00 2001 From: jiangwei Date: Thu, 10 Apr 2025 10:46:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dstoull=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=E6=8A=9B=E5=87=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangwei --- include/utilities.h | 1 + src/subcommand_record.cpp | 15 +++++++++++++-- src/utilities.cpp | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/utilities.h b/include/utilities.h index 7cdb85d..cb14f0d 100644 --- a/include/utilities.h +++ b/include/utilities.h @@ -310,6 +310,7 @@ bool IsBeta(); bool IsAllowProfilingUid(); bool IsHiviewCall(); bool PowerOfTwo(uint64_t n); +bool IsNumeric(const std::string& str); const std::string HMKERNEL = "HongMeng"; diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index fc54241..51e9d25 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -180,9 +180,20 @@ bool SubCommandRecord::GetSpeOptions() for (auto item: valueExpressions) { std::vector expressions = StringSplit(item, "="); size_t itemNum = 2; - if (expressions.size() == itemNum) { + if (expressions.size() == itemNum && (IsNumeric(expressions[1]) || IsHexDigits(expressions[1]))) { std::string name = expressions[0]; - unsigned long long num = std::stoull(expressions[1]); + uint64_t num = 0; + char *endPtr = nullptr; + errno = 0; + if (IsNumeric(expressions[1])) { + num = std::strtoull(expressions[1].c_str(), &endPtr, 10); // 10 : decimal scale + } else { + num = std::strtoull(expressions[1].c_str(), &endPtr, NUMBER_FORMAT_HEX_BASE); + } + if (endPtr == expressions[1].c_str() || *endPtr != '\0' || errno != 0) { + HLOGE("string to uint64_t failed, expressions[1]: %s", expressions[1].c_str()); + return false; + } if (speOptMap_.find(name) != speOptMap_.end()) { speOptMap_[name] = num; } diff --git a/src/utilities.cpp b/src/utilities.cpp index 2ba0d68..552e291 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -891,6 +891,20 @@ bool IsApplicationEncryped(const int pid) return false; #endif } + +bool IsNumeric(const std::string& str) +{ + std::istringstream iss(str); + int number; + char trailingCharacter; + if (!(iss >> number)) { + return false; + } + if (iss >> trailingCharacter) { + return false; + } + return true; +} } // namespace HiPerf } // namespace Developtools } // namespace OHOS -- Gitee From b5c6a6c191d3e7683845c8dcef518be34523ee6f Mon Sep 17 00:00:00 2001 From: jiangwei Date: Tue, 29 Apr 2025 06:41:17 +0000 Subject: [PATCH 2/2] update src/subcommand_record.cpp. Signed-off-by: jiangwei --- src/subcommand_record.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index 51e9d25..e38606a 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -192,7 +192,7 @@ bool SubCommandRecord::GetSpeOptions() } if (endPtr == expressions[1].c_str() || *endPtr != '\0' || errno != 0) { HLOGE("string to uint64_t failed, expressions[1]: %s", expressions[1].c_str()); - return false; + continue; } if (speOptMap_.find(name) != speOptMap_.end()) { speOptMap_[name] = num; -- Gitee