From fbe8dbce5e91219d262f971d6ec24406d4902559 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 9 May 2025 08:16:03 +0200 Subject: [PATCH 1/4] Adjust for renamed function flavor in Spicy development version With zeek/spicy#2048 the flavor for functions was renamed from `Standard` to `Function`. This patch adapts the code for that while still allowing using earlier Spicy versions. --- auxil/spicy | 2 +- src/spicy/spicyz/glue-compiler.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/auxil/spicy b/auxil/spicy index ceb058a517..abd484926d 160000 --- a/auxil/spicy +++ b/auxil/spicy @@ -1 +1 @@ -Subproject commit ceb058a517e1feb042ebbaf6fb80facf4b15a23d +Subproject commit abd484926df173d8351bc1269a5ac0ad848b3d6e diff --git a/src/spicy/spicyz/glue-compiler.cc b/src/spicy/spicyz/glue-compiler.cc index 1ee465a149..89a1b2e902 100644 --- a/src/spicy/spicyz/glue-compiler.cc +++ b/src/spicy/spicyz/glue-compiler.cc @@ -1120,11 +1120,15 @@ bool GlueCompiler::compile() { preinit_body.addCall("zeek_rt::register_spicy_module_end", {}); if ( ! preinit_body.empty() ) { +#if SPICY_VERSION_NUMBER >= 11400 + constexpr auto zeek_preinit_flavor = hilti::type::function::Flavor::Function; +#else + constexpr auto zeek_preinit_flavor = hilti::type::function::Flavor::Standard; +#endif auto preinit_function = builder()->function(hilti::ID("zeek_preinit"), builder()->qualifiedType(builder()->typeVoid(), hilti::Constness::Const), {}, - preinit_body.block(), hilti::type::function::Flavor::Standard, - hilti::declaration::Linkage::PreInit); + preinit_body.block(), zeek_preinit_flavor, hilti::declaration::Linkage::PreInit); init_module->add(context(), preinit_function); } From 9355512adc7a0eb801a1a9ffad974049360abd85 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 9 May 2025 08:19:13 +0200 Subject: [PATCH 2/4] Remove unneeded copies in Spicy plugin glue compiler --- src/spicy/spicyz/glue-compiler.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spicy/spicyz/glue-compiler.cc b/src/spicy/spicyz/glue-compiler.cc index 89a1b2e902..5db50b6f3b 100644 --- a/src/spicy/spicyz/glue-compiler.cc +++ b/src/spicy/spicyz/glue-compiler.cc @@ -1046,7 +1046,7 @@ bool GlueCompiler::compile() { preinit_body.addCall("zeek_rt::register_file_analyzer", {builder()->stringMutable(a.name.str()), builder()->vector(hilti::util::transform(a.mime_types, - [&](auto m) { + [&](const auto& m) { return builder() ->stringMutable(m) ->template as(); @@ -1100,7 +1100,7 @@ bool GlueCompiler::compile() { m->spicy_module->add(context(), import_); // Create a vector of unique parent paths from all EVTs files going into this module. - auto search_dirs = hilti::util::transform(m->evts, [](auto p) { return p.parent_path(); }); + auto search_dirs = hilti::util::transform(m->evts, [](const auto& p) { return p.parent_path(); }); auto search_dirs_vec = std::vector(search_dirs.begin(), search_dirs.end()); // Import any dependencies. From 37b095f39bd29e13c1dd5b7459efdcef19ff8821 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 9 May 2025 08:21:39 +0200 Subject: [PATCH 3/4] Fix clang-tidy `performance-enum-size` reports in Spicy plugin's glue compiler --- src/spicy/spicyz/glue-compiler.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spicy/spicyz/glue-compiler.cc b/src/spicy/spicyz/glue-compiler.cc index 5db50b6f3b..a796ae51c9 100644 --- a/src/spicy/spicyz/glue-compiler.cc +++ b/src/spicy/spicyz/glue-compiler.cc @@ -343,7 +343,7 @@ hilti::Result GlueCompiler::getNextEvtBlock(std::istream& in, int* std::string chunk; // Parser need to track whether we are inside a string or a comment. - enum State { Default, InComment, InString } state = Default; + enum State : char { Default, InComment, InString } state = Default; char prev = '\0'; while ( true ) { @@ -666,7 +666,7 @@ glue::ProtocolAnalyzer GlueCompiler::parseProtocolAnalyzer(const std::string& ch eat_token(chunk, &i, ":"); - enum { orig, resp, both } dir; + enum Dir : char { orig, resp, both } dir; while ( true ) { if ( looking_at(chunk, i, "parse") ) { From 24071118eb06d6fd25d27ccca258a8c2ac857f83 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 9 May 2025 09:12:32 +0200 Subject: [PATCH 4/4] Fix clang-tidy `bugprone-inc-dec-in-conditions` report in Spicy plugins glue compiler --- src/spicy/spicyz/glue-compiler.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/spicy/spicyz/glue-compiler.cc b/src/spicy/spicyz/glue-compiler.cc index a796ae51c9..8e14b70ef2 100644 --- a/src/spicy/spicyz/glue-compiler.cc +++ b/src/spicy/spicyz/glue-compiler.cc @@ -38,12 +38,8 @@ static std::string::size_type looking_at(const std::string& chunk, std::string:: const std::string_view& token) { eat_spaces(chunk, &i); - for ( char j : token ) { - if ( i >= chunk.size() || chunk[i++] != j ) - return 0; - } - - return i; + bool token_at_position = i < chunk.size() && token == std::string_view(chunk).substr(i, token.size()); + return token_at_position ? i + token.size() : 0; } static void eat_token(const std::string& chunk, std::string::size_type* i, const std::string_view& token) {