From e2ca97b86bd974f65157cab1b924853b996fa627 Mon Sep 17 00:00:00 2001 From: wanghongen Date: Sat, 21 Jun 2025 18:49:40 +0800 Subject: [PATCH 1/6] =?UTF-8?q?5.1.1hdf=E5=91=8A=E8=AD=A6=E6=B8=85?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanghongen --- framework/tools/hc-gen/src/ast.cpp | 2 +- framework/tools/hc-gen/src/ast.h | 2 +- framework/tools/hc-gen/src/bytecode_gen.cpp | 16 ++++++++++++++-- framework/tools/hc-gen/src/lexer.cpp | 9 ++++++++- framework/tools/hc-gen/src/macro_gen.cpp | 8 +++++++- framework/tools/hc-gen/src/option.cpp | 2 +- framework/tools/hc-gen/src/startup_cfg_gen.cpp | 14 ++++++++++---- framework/tools/hc-gen/src/text_gen.cpp | 3 +++ 8 files changed, 45 insertions(+), 11 deletions(-) diff --git a/framework/tools/hc-gen/src/ast.cpp b/framework/tools/hc-gen/src/ast.cpp index 2617274cd..2471fb9b3 100644 --- a/framework/tools/hc-gen/src/ast.cpp +++ b/framework/tools/hc-gen/src/ast.cpp @@ -716,7 +716,7 @@ bool ConfigNode::IsBaseNode() return true; } -ConfigTerm::ConfigTerm(const ConfigTerm &term) : ConfigTerm(term.name_, nullptr) +ConfigTerm::ConfigTerm(const ConfigTerm &term) : ConfigTerm(term.name_, nullptr), signNum_(0) { AstObject::AddChild(AstObjectFactory::Build(term.child_)); src_ = term.src_; diff --git a/framework/tools/hc-gen/src/ast.h b/framework/tools/hc-gen/src/ast.h index 17a4b1411..5938a6427 100644 --- a/framework/tools/hc-gen/src/ast.h +++ b/framework/tools/hc-gen/src/ast.h @@ -383,7 +383,7 @@ public: return false; } } else { - uint32_t ret = forwardCallback(roundWalkObj, walkDepth); + uint32_t ret = static_cast(forwardCallback(roundWalkObj, walkDepth)); /* when callback return EASTWALKBREAK, not walk current's child */ if (ret && ret != EASTWALKBREAK) { return false; diff --git a/framework/tools/hc-gen/src/bytecode_gen.cpp b/framework/tools/hc-gen/src/bytecode_gen.cpp index 99ca76b8f..2a2648a90 100644 --- a/framework/tools/hc-gen/src/bytecode_gen.cpp +++ b/framework/tools/hc-gen/src/bytecode_gen.cpp @@ -59,7 +59,13 @@ bool ByteCodeGen::Initialize() outFileName.append(".hcb"); } - ofs_.open(outFileName, std::ofstream::out | std::ofstream::binary); + char realpathStr[PATH_MAX] = {'\0'}; + if (realpath(outFileName, realpathStr) == nullptr) { + HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); + return false; + } + + ofs_.open(realpathStr, std::ofstream::out | std::ofstream::binary); if (!ofs_.is_open()) { Logger().Error() << "failed to open output file: " << outFileName; return false; @@ -267,7 +273,13 @@ bool ByteCodeGen::HexdumpInitialize(FILE *&in, FILE *&out) return false; } - out = fopen(hexdumpOutName.data(), "wb"); + char realpathStr[PATH_MAX] = {'\0'}; + if (realpath(hexdumpOutName.data(), realpathStr) == nullptr) { + HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); + return false; + } + + out = fopen(realpathStr, "wb"); if (out == nullptr) { fclose(in); in = nullptr; diff --git a/framework/tools/hc-gen/src/lexer.cpp b/framework/tools/hc-gen/src/lexer.cpp index e9e105660..892d6738e 100644 --- a/framework/tools/hc-gen/src/lexer.cpp +++ b/framework/tools/hc-gen/src/lexer.cpp @@ -40,7 +40,14 @@ bool Lexer::Initialize(const std::string &sourceName) bufferEnd_ = nullptr; lineno_ = 1; lineLoc_ = 1; - src_.open(srcName_->c_str(), std::ifstream::binary); + + char realpathStr[PATH_MAX] = {'\0'}; + if (realpath(srcName_->c_str(), realpathStr) == nullptr) { + HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); + return false; + } + + src_.open(realpathStr, std::ifstream::binary); if (!src_.is_open()) { Logger().Error() << "Failed to open source file: " << srcName_->data(); return false; diff --git a/framework/tools/hc-gen/src/macro_gen.cpp b/framework/tools/hc-gen/src/macro_gen.cpp index 4ce4eeb4e..e47e06f97 100644 --- a/framework/tools/hc-gen/src/macro_gen.cpp +++ b/framework/tools/hc-gen/src/macro_gen.cpp @@ -82,8 +82,14 @@ bool MacroGen::Initialize() if (outFileName.find(".h") == std::string::npos) { outFileName.append(".h"); } + + char realpathStr[PATH_MAX] = {'\0'}; + if (realpath(outFileName, realpathStr) == nullptr) { + HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); + return false; + } - ofs_.open(outFileName, std::ofstream::out | std::ofstream::binary); + ofs_.open(realpathStr, std::ofstream::out | std::ofstream::binary); if (!ofs_.is_open()) { Logger().Error() << "failed to open output file: " << outFileName; return false; diff --git a/framework/tools/hc-gen/src/option.cpp b/framework/tools/hc-gen/src/option.cpp index c661d3301..b7ebe1b9f 100644 --- a/framework/tools/hc-gen/src/option.cpp +++ b/framework/tools/hc-gen/src/option.cpp @@ -42,7 +42,7 @@ Option &Option::Parse(int argc, char **argv) break; } - if (optind >= argc) { + if (optind < 0 || optind >= argc) { Logger().Error() << "Miss input file name"; SetOptionError(); break; diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.cpp b/framework/tools/hc-gen/src/startup_cfg_gen.cpp index bcb5d2f18..0648ab356 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.cpp +++ b/framework/tools/hc-gen/src/startup_cfg_gen.cpp @@ -87,7 +87,13 @@ bool StartupCfgGen::Initialize() outFileName = Util::File::StripSuffix(outFileName).append(".cfg"); outFileName_ = Util::File::FileNameBase(outFileName); - ofs_.open(outFileName, std::ofstream::out | std::ofstream::binary); + char realpathStr[PATH_MAX] = {'\0'}; + if (realpath(outFileName, realpathStr) == nullptr) { + HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); + return false; + } + + ofs_.open(realpathStr, std::ofstream::out | std::ofstream::binary); if (!ofs_.is_open()) { Logger().Error() << "failed to open output file: " << outFileName; return false; @@ -191,8 +197,8 @@ void StartupCfgGen::HostInfoOutput(const std::string &name, bool end) if (!hostInfoMap_[name].initConfig.empty()) { for (auto &info : hostInfoMap_[name].initConfig) { - int firstQuotePos = info.find("\""); - int secondQuotePos = info.find("\"", firstQuotePos + 1); + unsigned int firstQuotePos = info.find("\""); + unsigned int secondQuotePos = info.find("\"", firstQuotePos + 1); configedKeywords.insert(info.substr(firstQuotePos + 1, secondQuotePos - (firstQuotePos + 1))); } } @@ -365,7 +371,7 @@ void StartupCfgGen::GetMallocOpt(const std::shared_ptr &hostInfo, std::vector mallocOptions = {}; GetConfigVector(term, mallocOptions); for (auto mallocOption : mallocOptions) { - int separatorPos = mallocOption.find(MALLOPT_SEPARATOR); + unsigned int separatorPos = mallocOption.find(MALLOPT_SEPARATOR); std::string malloptKey = mallocOption.substr(0, separatorPos); std::string malloptValue = mallocOption.substr(separatorPos + 1, mallocOption.length() - (separatorPos + 1)); diff --git a/framework/tools/hc-gen/src/text_gen.cpp b/framework/tools/hc-gen/src/text_gen.cpp index 6ac78346a..2a55479d1 100644 --- a/framework/tools/hc-gen/src/text_gen.cpp +++ b/framework/tools/hc-gen/src/text_gen.cpp @@ -369,6 +369,9 @@ uint32_t TextGen::ImplementCloseBraceGen(const std::shared_ptr &objec if (!object->IsNode() || ConfigNode::CastFrom(object)->GetNodeType() == NODE_INHERIT) { return NOERR; } + if (depth < 0 && depth != -1) { + return NOERR; + } if (object == ast_->GetAstRoot()) { ofs_ << "};\n"; } else { -- Gitee From 3d7bd1157e0fdb5c0a90c57616d5aadf00b5f6b9 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Sat, 21 Jun 2025 15:41:24 +0000 Subject: [PATCH 2/6] update framework/tools/hc-gen/src/ast.cpp. Signed-off-by: wanghongenaf --- framework/tools/hc-gen/src/ast.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/tools/hc-gen/src/ast.cpp b/framework/tools/hc-gen/src/ast.cpp index 2471fb9b3..2617274cd 100644 --- a/framework/tools/hc-gen/src/ast.cpp +++ b/framework/tools/hc-gen/src/ast.cpp @@ -716,7 +716,7 @@ bool ConfigNode::IsBaseNode() return true; } -ConfigTerm::ConfigTerm(const ConfigTerm &term) : ConfigTerm(term.name_, nullptr), signNum_(0) +ConfigTerm::ConfigTerm(const ConfigTerm &term) : ConfigTerm(term.name_, nullptr) { AstObject::AddChild(AstObjectFactory::Build(term.child_)); src_ = term.src_; -- Gitee From 52736c73e1404349eec03434afcf4e1a92c2ec4a Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Sun, 22 Jun 2025 01:55:34 +0000 Subject: [PATCH 3/6] update framework/tools/hc-gen/src/bytecode_gen.cpp. Signed-off-by: wanghongenaf --- framework/tools/hc-gen/src/bytecode_gen.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/framework/tools/hc-gen/src/bytecode_gen.cpp b/framework/tools/hc-gen/src/bytecode_gen.cpp index 2a2648a90..99ca76b8f 100644 --- a/framework/tools/hc-gen/src/bytecode_gen.cpp +++ b/framework/tools/hc-gen/src/bytecode_gen.cpp @@ -59,13 +59,7 @@ bool ByteCodeGen::Initialize() outFileName.append(".hcb"); } - char realpathStr[PATH_MAX] = {'\0'}; - if (realpath(outFileName, realpathStr) == nullptr) { - HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); - return false; - } - - ofs_.open(realpathStr, std::ofstream::out | std::ofstream::binary); + ofs_.open(outFileName, std::ofstream::out | std::ofstream::binary); if (!ofs_.is_open()) { Logger().Error() << "failed to open output file: " << outFileName; return false; @@ -273,13 +267,7 @@ bool ByteCodeGen::HexdumpInitialize(FILE *&in, FILE *&out) return false; } - char realpathStr[PATH_MAX] = {'\0'}; - if (realpath(hexdumpOutName.data(), realpathStr) == nullptr) { - HDF_LOGE("%{public}s:realpath failed.ret = %{public}s", __func__, strerror(errno)); - return false; - } - - out = fopen(realpathStr, "wb"); + out = fopen(hexdumpOutName.data(), "wb"); if (out == nullptr) { fclose(in); in = nullptr; -- Gitee From 44ae65e09aa34dc64cee3df400b18d301bccdb41 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Sun, 22 Jun 2025 10:26:13 +0000 Subject: [PATCH 4/6] update framework/tools/hc-gen/src/lexer.cpp. Signed-off-by: wanghongenaf --- framework/tools/hc-gen/src/lexer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/tools/hc-gen/src/lexer.cpp b/framework/tools/hc-gen/src/lexer.cpp index 892d6738e..3b30dc2f1 100644 --- a/framework/tools/hc-gen/src/lexer.cpp +++ b/framework/tools/hc-gen/src/lexer.cpp @@ -12,7 +12,7 @@ #include #include "logger.h" - +#define PATH_MAX 128 using namespace OHOS::Hardware; static constexpr int BINARY_NUM = 2; -- Gitee From 5e2f32822fc428fac8b4efa975c72f75b81946a3 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Sun, 22 Jun 2025 10:27:08 +0000 Subject: [PATCH 5/6] update framework/tools/hc-gen/src/macro_gen.cpp. Signed-off-by: wanghongenaf --- framework/tools/hc-gen/src/macro_gen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/tools/hc-gen/src/macro_gen.cpp b/framework/tools/hc-gen/src/macro_gen.cpp index e47e06f97..7652ae0d5 100644 --- a/framework/tools/hc-gen/src/macro_gen.cpp +++ b/framework/tools/hc-gen/src/macro_gen.cpp @@ -12,7 +12,7 @@ #include "file.h" #include "logger.h" #include "macro_gen.h" - +#define PATH_MAX 128 using namespace OHOS::Hardware; constexpr static const char *FILE_HEAD_COMMENT = -- Gitee From e7126377f0cd524f8d177d42d46ed85816eca163 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Sun, 22 Jun 2025 10:27:39 +0000 Subject: [PATCH 6/6] update framework/tools/hc-gen/src/startup_cfg_gen.cpp. Signed-off-by: wanghongenaf --- framework/tools/hc-gen/src/startup_cfg_gen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.cpp b/framework/tools/hc-gen/src/startup_cfg_gen.cpp index 0648ab356..a15157a33 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.cpp +++ b/framework/tools/hc-gen/src/startup_cfg_gen.cpp @@ -13,7 +13,7 @@ #include "ast.h" #include "file.h" #include "logger.h" - +#define PATH_MAX 128 using namespace OHOS::Hardware; static constexpr const char *BOOT_CONFIG_TOP = -- Gitee