From 26235e9f105baf3a39232575582406c01662ef51 Mon Sep 17 00:00:00 2001 From: ahuo Date: Wed, 10 Sep 2025 07:15:39 +0000 Subject: [PATCH 1/2] fix: check path attribute before using --- src/xml_parsing.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp index 8b9ce95a1..97cd2a08f 100644 --- a/src/xml_parsing.cpp +++ b/src/xml_parsing.cpp @@ -261,10 +261,15 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes) break; } + const char* path_attr = incl_node->Attribute("path"); + if (!path_attr) { + throw RuntimeError("Invalid tag: missing 'path' attribute"); + } + #if __bt_cplusplus >= 202002L - auto file_path(std::filesystem::path(incl_node->Attribute("path"))); + auto file_path{ std::filesystem::path(path_attr) }; #else - auto file_path(std::filesystem::u8path(incl_node->Attribute("path"))); + auto file_path{ std::filesystem::u8path(path_attr) }; #endif const char* ros_pkg_relative_path = incl_node->Attribute("ros_pkg"); From 6c217e7da1d3d53143b89f4ff140e6173ab062c5 Mon Sep 17 00:00:00 2001 From: ahuo Date: Wed, 10 Sep 2025 08:09:54 +0000 Subject: [PATCH 2/2] style: format code --- src/xml_parsing.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp index 97cd2a08f..5a76e5e87 100644 --- a/src/xml_parsing.cpp +++ b/src/xml_parsing.cpp @@ -261,10 +261,11 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes) break; } - const char* path_attr = incl_node->Attribute("path"); - if (!path_attr) { - throw RuntimeError("Invalid tag: missing 'path' attribute"); - } + const char* path_attr = incl_node->Attribute("path"); + if (!path_attr) + { + throw RuntimeError("Invalid tag: missing 'path' attribute"); + } #if __bt_cplusplus >= 202002L auto file_path{ std::filesystem::path(path_attr) };