Fix clang-tidy bugprone-macro-parentheses warnings

This commit is contained in:
Tim Wojtulewicz 2025-04-16 13:25:26 -07:00
parent 1d315a3847
commit 9e83759e83
9 changed files with 22 additions and 16 deletions

View file

@ -4,4 +4,5 @@ Checks: [-*,
bugprone-implicit-widening-of-multiplication-result,
bugprone-incorrect-division,
bugprone-incorrect-roundings,
bugprone-macro-parentheses,
]

View file

@ -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<ipaddr32_t, ipaddr32_t>::iterator p = mapping.find(addr);

View file

@ -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(<=)

View file

@ -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;
}

View file

@ -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

View file

@ -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 {

View file

@ -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 {

View file

@ -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<VectorType>(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<type>(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.

View file

@ -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; \