bifcl: Fix clang-tidy warnings

This commit is contained in:
Tim Wojtulewicz 2025-08-21 15:33:24 +00:00
parent 22d82edc74
commit d3ac12da68
5 changed files with 21 additions and 11 deletions

View file

@ -12,8 +12,15 @@ add_flex_bison_dependency(BIFScanner BIFParser)
set(bifcl_SRCS ${BISON_BIFParser_INPUT} ${FLEX_BIFScanner_INPUT} ${BISON_BIFParser_OUTPUTS} set(bifcl_SRCS ${BISON_BIFParser_INPUT} ${FLEX_BIFScanner_INPUT} ${BISON_BIFParser_OUTPUTS}
${FLEX_BIFScanner_OUTPUTS} bif_arg.cc module_util.cc) ${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}) add_executable(bifcl ${bifcl_SRCS})
target_include_directories(bifcl BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(bifcl BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
zeek_target_add_linters(bifcl)
if (MSVC) if (MSVC)
target_compile_options(bifcl PUBLIC "/J") # Similar to -funsigned-char on other platforms target_compile_options(bifcl PUBLIC "/J") # Similar to -funsigned-char on other platforms

View file

@ -1,6 +1,6 @@
// See the file "COPYING" in the main distribution directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
#include "bif_arg.h" #include "include/bif_arg.h"
#include <cstring> #include <cstring>
@ -16,6 +16,7 @@ static struct {
const char* constructor; const char* constructor;
const char* ctor_smart; const char* ctor_smart;
} builtin_func_arg_type[] = { } 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, \ #define DEFINE_BIF_TYPE(id, bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, \
constructor, ctor_smart) \ constructor, ctor_smart) \
{#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},

View file

@ -175,7 +175,7 @@ FILE* open_output_file(const char* surfix) {
FILE* fp; FILE* fp;
snprintf(fn, sizeof(fn), "%s.%s", input_filename, surfix); 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); fprintf(stderr, "Error: cannot open file: %s\n", fn);
err_exit(); err_exit();
} }
@ -216,7 +216,7 @@ void init_alternative_mode() {
fprintf(fp_func_register, "// %s\n\n", auto_gen_comment); fprintf(fp_func_register, "// %s\n\n", auto_gen_comment);
static char guard[1024]; 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"); fprintf(stderr, "Error: cannot get current working directory\n");
err_exit(); err_exit();
} }
@ -341,7 +341,7 @@ int main(int argc, char* argv[]) {
input_filename = input_filename_with_path = argv[i]; input_filename = input_filename_with_path = argv[i];
char* slash = strrchr(input_filename, '/'); 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); fprintf(stderr, "Error: cannot open file: %s\n", input_filename);
/* no output files open. can simply exit */ /* no output files open. can simply exit */
exit(1); exit(1);

View file

@ -164,6 +164,7 @@ static struct {
const char* constructor; const char* constructor;
const char* ctor_smatr; const char* ctor_smatr;
} builtin_types[] = { } 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) \ #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}, {bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart},
#include "bif_type.def" #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()); 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 "); fprintf(fp, "\t ");
args[i]->PrintValConstructor(fp); arg->PrintValConstructor(fp);
fprintf(fp, ",\n"); fprintf(fp, ",\n");
if ( args[i]->Type() == TYPE_CONNECTION ) { if ( arg->Type() == TYPE_CONNECTION ) {
if ( connection_arg == nullptr ) if ( connection_arg == nullptr )
connection_arg = args[i]; connection_arg = arg;
else { else {
// We are seeing two connection type arguments. // We are seeing two connection type arguments.
yywarn( 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 ';' 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); set_decl_name($3);
int typeidx = get_type_index($7); int typeidx = get_type_index($7);
char accessor[1024]; char accessor[1024];
@ -504,11 +505,11 @@ opt_attr_list:
; ;
func_prefix: TOK_FUNCTION func_prefix: TOK_FUNCTION
{ set_definition_type(FUNC_DEF, 0); } { set_definition_type(FUNC_DEF, nullptr); }
; ;
event_prefix: TOK_EVENT event_prefix: TOK_EVENT
{ set_definition_type(EVENT_DEF, 0); } { set_definition_type(EVENT_DEF, nullptr); }
; ;
end_of_head: /* nothing */ end_of_head: /* nothing */

View file

@ -6,6 +6,7 @@
#include <cstdio> #include <cstdio>
enum builtin_func_arg_type : uint8_t { 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, \ #define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, \
constructor, ctor_smart) \ constructor, ctor_smart) \
id, id,