diff --git a/.clang-tidy b/.clang-tidy index 025098cceb..aafda51013 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,4 +4,5 @@ Checks: [-*, bugprone-implicit-widening-of-multiplication-result, bugprone-incorrect-division, bugprone-incorrect-roundings, + bugprone-macro-parentheses, ] diff --git a/src/Anon.cc b/src/Anon.cc index 022778c9c0..facc5dbbb2 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -54,7 +54,7 @@ static int bi_ffs(uint32_t value) { return add + bvals[value & 0xf]; } -#define first_n_bit_mask(n) (~(0xFFFFFFFFU >> n)) +static inline uint64_t first_n_bit_mask(int n) { return ~(0xFFFFFFFFU >> n); } ipaddr32_t AnonymizeIPAddr::Anonymize(ipaddr32_t addr) { std::map::iterator p = mapping.find(addr); diff --git a/src/Expr.cc b/src/Expr.cc index 74f4637fef..a0acb01b5e 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -892,11 +892,13 @@ ValPtr BinaryExpr::StringFold(Val* v1, Val* v2) const { switch ( tag ) { #undef DO_FOLD +// NOLINTBEGIN(bugprone-macro-parentheses) #define DO_FOLD(sense) \ { \ result = Bstr_cmp(s1, s2) sense 0; \ break; \ } + // NOLINTEND(bugprone-macro-parentheses) case EXPR_LT: DO_FOLD(<) case EXPR_LE: DO_FOLD(<=) diff --git a/src/Type.cc b/src/Type.cc index 9b318b3873..a9a072a20e 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -2155,10 +2155,6 @@ bool is_assignable(TypeTag t) { return false; } -#define CHECK_TYPE(t) \ - if ( t1 == t || t2 == t ) \ - return t; - TypeTag max_type(TypeTag t1, TypeTag t2) { if ( t1 == TYPE_INTERVAL || t1 == TYPE_TIME ) t1 = TYPE_DOUBLE; @@ -2166,9 +2162,12 @@ TypeTag max_type(TypeTag t1, TypeTag t2) { t2 = TYPE_DOUBLE; if ( BothArithmetic(t1, t2) ) { - CHECK_TYPE(TYPE_DOUBLE); - CHECK_TYPE(TYPE_INT); - CHECK_TYPE(TYPE_COUNT); + if ( t1 == TYPE_DOUBLE || t2 == TYPE_DOUBLE ) + return TYPE_DOUBLE; + else if ( t1 == TYPE_INT || t2 == TYPE_INT ) + return TYPE_INT; + else if ( t1 == TYPE_COUNT || t2 == TYPE_COUNT ) + return TYPE_COUNT; return TYPE_COUNT; } diff --git a/src/analyzer/protocol/login/NVT.cc b/src/analyzer/protocol/login/NVT.cc index 23eb513972..1543bdd79d 100644 --- a/src/analyzer/protocol/login/NVT.cc +++ b/src/analyzer/protocol/login/NVT.cc @@ -9,7 +9,7 @@ #include "zeek/analyzer/protocol/login/events.bif.h" #include "zeek/analyzer/protocol/tcp/TCP.h" -#define IS_3_BYTE_OPTION(c) (c >= 251 && c <= 254) +#define IS_3_BYTE_OPTION(c) ((c) >= 251 && (c) <= 254) #define TELNET_OPT_SB 250 #define TELNET_OPT_SE 240 diff --git a/src/analyzer/protocol/netbios/NetbiosSSN.cc b/src/analyzer/protocol/netbios/NetbiosSSN.cc index 9218a7c2cb..c9106537b2 100644 --- a/src/analyzer/protocol/netbios/NetbiosSSN.cc +++ b/src/analyzer/protocol/netbios/NetbiosSSN.cc @@ -13,11 +13,11 @@ constexpr double netbios_ssn_session_timeout = 15.0; #define MAKE_INT16(dest, src) \ - dest = *src; \ - dest <<= 8; \ - src++; \ - dest |= *src; \ - src++; + (dest) = *(src); \ + (dest) <<= 8; \ + (src)++; \ + (dest) |= *(src); \ + (src)++; namespace zeek::analyzer::netbios_ssn { namespace detail { diff --git a/src/analyzer/protocol/smtp/SMTP.cc b/src/analyzer/protocol/smtp/SMTP.cc index ac910f667f..8edc14b286 100644 --- a/src/analyzer/protocol/smtp/SMTP.cc +++ b/src/analyzer/protocol/smtp/SMTP.cc @@ -20,7 +20,7 @@ static const char* smtp_cmd_word[] = { static const char* unknown_cmd = "(UNKNOWN)"; -#define SMTP_CMD_WORD(code) ((code >= 0) ? smtp_cmd_word[code] : unknown_cmd) +#define SMTP_CMD_WORD(code) (((code) >= 0) ? smtp_cmd_word[code] : unknown_cmd) namespace zeek::analyzer::smtp { diff --git a/src/script_opt/CPP/RuntimeVec.cc b/src/script_opt/CPP/RuntimeVec.cc index 7c6e6ab717..e7d61b223d 100644 --- a/src/script_opt/CPP/RuntimeVec.cc +++ b/src/script_opt/CPP/RuntimeVec.cc @@ -56,6 +56,7 @@ static VectorTypePtr base_vector_type__CPP(const VectorTypePtr& vt, bool is_bool // is an optional kernel to use for vectors whose underlying type // is "double". It needs to be optional because C++ will (rightfully) // complain about applying certain C++ unary operations to doubles. +// NOLINTBEGIN(bugprone-macro-parentheses) #define VEC_OP1(name, op, double_kernel) \ VectorValPtr vec_op_##name##__CPP(const VectorValPtr& v, const TypePtr& t) { \ auto vt = base_vector_type__CPP(cast_intrusive(t)); \ @@ -79,6 +80,7 @@ static VectorTypePtr base_vector_type__CPP(const VectorTypePtr& vt, bool is_bool \ return v_result; \ } +// NOLINTEND(bugprone-macro-parentheses) // Instantiates a double_kernel for a given operation. #define VEC_OP1_WITH_DOUBLE(name, op) \ @@ -96,6 +98,7 @@ VEC_OP1(comp, ~, ) // A kernel for applying a binary operation element-by-element to two // vectors of a given low-level type. +// NOLINTBEGIN(bugprone-macro-parentheses) #define VEC_OP2_KERNEL(accessor, type, op, zero_check) \ for ( unsigned int i = 0; i < v1->Size(); ++i ) { \ auto v1_i = v1->ValAt(i); \ @@ -107,6 +110,7 @@ VEC_OP1(comp, ~, ) v_result->Assign(i, make_intrusive(v1_i->accessor() op v2_i->accessor())); \ } \ } +// NOLINTEND(bugprone-macro-parentheses) // Analogous to VEC_OP1, instantiates a function for a given binary operation, // with customizable kernels for "int" and "double" operations. diff --git a/src/script_opt/ZAM/ZBody.cc b/src/script_opt/ZAM/ZBody.cc index 689f269730..4cb96716ce 100644 --- a/src/script_opt/ZAM/ZBody.cc +++ b/src/script_opt/ZAM/ZBody.cc @@ -202,7 +202,7 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con auto vi = (*v[i]).rhs_accessor; \ if ( ov_check(vi) ) { \ std::string err = "overflow promoting from "; \ - err += ov_err; \ + err += (ov_err); \ err += " arithmetic value"; \ /* The run-time error will throw an exception, so recover intermediary memory. */ \ delete res_zv; \