From d3ac12da6879569c2c15ccc282514cb575f9799a Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 21 Aug 2025 15:33:24 +0000 Subject: [PATCH] bifcl: Fix clang-tidy warnings --- tools/bifcl/CMakeLists.txt | 7 +++++++ tools/bifcl/bif_arg.cc | 3 ++- tools/bifcl/builtin-func.l | 6 +++--- tools/bifcl/builtin-func.y | 15 ++++++++------- tools/bifcl/include/bif_arg.h | 1 + 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tools/bifcl/CMakeLists.txt b/tools/bifcl/CMakeLists.txt index 9896236429..215db932d4 100644 --- a/tools/bifcl/CMakeLists.txt +++ b/tools/bifcl/CMakeLists.txt @@ -12,8 +12,15 @@ add_flex_bison_dependency(BIFScanner BIFParser) set(bifcl_SRCS ${BISON_BIFParser_INPUT} ${FLEX_BIFScanner_INPUT} ${BISON_BIFParser_OUTPUTS} ${FLEX_BIFScanner_OUTPUTS} bif_arg.cc module_util.cc) +set(bifcl_bison_generated_files + ${CMAKE_CURRENT_BINARY_DIR}/bif_parse.cc ${CMAKE_CURRENT_BINARY_DIR}/bif_parse.h + ${CMAKE_CURRENT_BINARY_DIR}/bif_lex.cc) + +set_source_files_properties(${bifcl_bison_generated_files} PROPERTIES SKIP_LINTING ON) + add_executable(bifcl ${bifcl_SRCS}) target_include_directories(bifcl BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +zeek_target_add_linters(bifcl) if (MSVC) target_compile_options(bifcl PUBLIC "/J") # Similar to -funsigned-char on other platforms diff --git a/tools/bifcl/bif_arg.cc b/tools/bifcl/bif_arg.cc index a75d480b9a..9547d42742 100644 --- a/tools/bifcl/bif_arg.cc +++ b/tools/bifcl/bif_arg.cc @@ -1,6 +1,6 @@ // See the file "COPYING" in the main distribution directory for copyright. -#include "bif_arg.h" +#include "include/bif_arg.h" #include @@ -16,6 +16,7 @@ static struct { const char* constructor; const char* ctor_smart; } builtin_func_arg_type[] = { +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEFINE_BIF_TYPE(id, bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, \ constructor, ctor_smart) \ {#id, bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart}, diff --git a/tools/bifcl/builtin-func.l b/tools/bifcl/builtin-func.l index 48fed7509f..6b59d9ea43 100644 --- a/tools/bifcl/builtin-func.l +++ b/tools/bifcl/builtin-func.l @@ -175,7 +175,7 @@ FILE* open_output_file(const char* surfix) { FILE* fp; snprintf(fn, sizeof(fn), "%s.%s", input_filename, surfix); - if ( (fp = fopen(fn, "w")) == NULL ) { + if ( fp = fopen(fn, "w"); fp == nullptr ) { fprintf(stderr, "Error: cannot open file: %s\n", fn); err_exit(); } @@ -216,7 +216,7 @@ void init_alternative_mode() { fprintf(fp_func_register, "// %s\n\n", auto_gen_comment); static char guard[1024]; - if ( getcwd(guard, sizeof(guard)) == NULL ) { + if ( getcwd(guard, sizeof(guard)) == nullptr ) { fprintf(stderr, "Error: cannot get current working directory\n"); err_exit(); } @@ -341,7 +341,7 @@ int main(int argc, char* argv[]) { input_filename = input_filename_with_path = argv[i]; char* slash = strrchr(input_filename, '/'); - if ( (fp_input = fopen(input_filename, "r")) == NULL ) { + if ( fp_input = fopen(input_filename, "r"); fp_input == nullptr ) { fprintf(stderr, "Error: cannot open file: %s\n", input_filename); /* no output files open. can simply exit */ exit(1); diff --git a/tools/bifcl/builtin-func.y b/tools/bifcl/builtin-func.y index 3c4b7bd221..d1a8244dc6 100644 --- a/tools/bifcl/builtin-func.y +++ b/tools/bifcl/builtin-func.y @@ -164,6 +164,7 @@ static struct { const char* constructor; const char* ctor_smatr; } builtin_types[] = { +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEFINE_BIF_TYPE(id, bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart) \ {bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart}, #include "bif_type.def" @@ -238,14 +239,14 @@ static void print_event_c_body(FILE * fp) { fprintf(fp, "\tzeek::event_mgr.Enqueue(%s, zeek::Args{\n", decl.c_fullname.c_str()); - for ( int i = 0; i < (int)args.size(); ++i ) { + for ( const auto& arg : args ) { fprintf(fp, "\t "); - args[i]->PrintValConstructor(fp); + arg->PrintValConstructor(fp); fprintf(fp, ",\n"); - if ( args[i]->Type() == TYPE_CONNECTION ) { + if ( arg->Type() == TYPE_CONNECTION ) { if ( connection_arg == nullptr ) - connection_arg = args[i]; + connection_arg = arg; else { // We are seeing two connection type arguments. yywarn( @@ -453,7 +454,7 @@ enum_list: enum_list TOK_ID opt_ws ',' opt_ws const_def: TOK_CONST opt_ws TOK_ID opt_ws ':' opt_ws TOK_ID opt_ws ';' { - set_definition_type(CONST_DEF, 0); + set_definition_type(CONST_DEF, nullptr); set_decl_name($3); int typeidx = get_type_index($7); char accessor[1024]; @@ -504,11 +505,11 @@ opt_attr_list: ; func_prefix: TOK_FUNCTION - { set_definition_type(FUNC_DEF, 0); } + { set_definition_type(FUNC_DEF, nullptr); } ; event_prefix: TOK_EVENT - { set_definition_type(EVENT_DEF, 0); } + { set_definition_type(EVENT_DEF, nullptr); } ; end_of_head: /* nothing */ diff --git a/tools/bifcl/include/bif_arg.h b/tools/bifcl/include/bif_arg.h index 57e38cbbd6..a7058380af 100644 --- a/tools/bifcl/include/bif_arg.h +++ b/tools/bifcl/include/bif_arg.h @@ -6,6 +6,7 @@ #include enum builtin_func_arg_type : uint8_t { +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, \ constructor, ctor_smart) \ id,