diff --git a/src/script_opt/ZAM/BuiltIn.cc b/src/script_opt/ZAM/BuiltIn.cc index 7cf0794d0a..8df4c6ce1c 100644 --- a/src/script_opt/ZAM/BuiltIn.cc +++ b/src/script_opt/ZAM/BuiltIn.cc @@ -313,25 +313,25 @@ ZInstAux* ZAMCompiler::BuildCatAux(const ExprPList& args) switch ( t->Tag() ) { - TYPE_BOOL: - TYPE_INT: - TYPE_COUNT: - TYPE_DOUBLE: - TYPE_TIME: - TYPE_ENUM: - TYPE_PORT: - TYPE_ADDR: - TYPE_SUBNET: - ca = std::make_unique(t); - break; + case TYPE_BOOL: + case TYPE_INT: + case TYPE_COUNT: + case TYPE_DOUBLE: + case TYPE_TIME: + case TYPE_ENUM: + case TYPE_PORT: + case TYPE_ADDR: + case TYPE_SUBNET: + ca = std::make_unique(t); + break; - TYPE_STRING: - ca = std::make_unique(); - break; + case TYPE_STRING: + ca = std::make_unique(); + break; - TYPE_PATTERN: - ca = std::make_unique(); - break; + case TYPE_PATTERN: + ca = std::make_unique(); + break; default: ca = std::make_unique(t); diff --git a/src/script_opt/ZAM/BuiltInSupport.cc b/src/script_opt/ZAM/BuiltInSupport.cc index 7e26a3ff6c..463e7e4e9b 100644 --- a/src/script_opt/ZAM/BuiltInSupport.cc +++ b/src/script_opt/ZAM/BuiltInSupport.cc @@ -12,43 +12,43 @@ FixedCatArg::FixedCatArg(const TypePtr& _t) : t(_t) { switch ( t->Tag() ) { - TYPE_BOOL: - max_size = 1; - break; + case TYPE_BOOL: + max_size = 1; + break; - TYPE_INT: - max_size = 20; // sufficient for 64 bits - break; + case TYPE_INT: + max_size = 20; // sufficient for 64 bits + break; - TYPE_COUNT: - max_size = 20; // sufficient for 64 bits - break; + case TYPE_COUNT: + max_size = 20; // sufficient for 64 bits + break; - TYPE_DOUBLE: - TYPE_TIME: - max_size = 32; // from modp_dtoa2 documentatino - break; + case TYPE_DOUBLE: + case TYPE_TIME: + max_size = 32; // from modp_dtoa2 documentatino + break; - TYPE_ENUM: - { - size_t n = 0; - for ( auto e : t->AsEnumType()->Names() ) - n += e.first.size(); - max_size = n; - break; - } + case TYPE_ENUM: + { + size_t n = 0; + for ( const auto& e : t->AsEnumType()->Names() ) + n += e.first.size(); + max_size = n; + break; + } - TYPE_PORT: - max_size = 5 + 1 + 7; // + / + "unknown - break; + case TYPE_PORT: + max_size = 5 + 1 + 7; // + / + "unknown + break; - TYPE_ADDR: - max_size = 39; // for IPv6 - break; + case TYPE_ADDR: + max_size = 39; // for IPv6 + break; - TYPE_SUBNET: - max_size = 39 + 1 + 3; // for IPv6 + / + <3-digits> - break; + case TYPE_SUBNET: + max_size = 39 + 1 + 3; // for IPv6 + / + <3-digits> + break; default: reporter->InternalError("bad type in FixedCatArg constructor"); @@ -64,85 +64,85 @@ void FixedCatArg::RenderInto(ZVal* zframe, int slot, char*& res) switch ( t->Tag() ) { - TYPE_BOOL: - *(res++) = z.AsInt() ? 'T' : 'F'; - break; + case TYPE_BOOL: + *(res++) = z.AsInt() ? 'T' : 'F'; + break; - TYPE_INT: - n = modp_litoa10(z.AsInt(), res); - res += n; - break; + case TYPE_INT: + n = modp_litoa10(z.AsInt(), res); + res += n; + break; - TYPE_COUNT: - n = modp_ulitoa10(z.AsCount(), res); - res += n; - break; + case TYPE_COUNT: + n = modp_ulitoa10(z.AsCount(), res); + res += n; + break; - TYPE_DOUBLE: - TYPE_TIME: - n = modp_dtoa2(z.AsDouble(), res, 6); - res += n; - break; + case TYPE_DOUBLE: + case TYPE_TIME: + n = modp_dtoa2(z.AsDouble(), res, 6); + res += n; + break; - TYPE_PATTERN: - text = z.AsPattern()->AsPattern()->PatternText(); - *(res++) = '/'; - strcpy(res, text); - res += strlen(text); - *(res++) = '/'; - break; + case TYPE_PATTERN: + text = z.AsPattern()->AsPattern()->PatternText(); + *(res++) = '/'; + strcpy(res, text); + res += strlen(text); + *(res++) = '/'; + break; - TYPE_ENUM: - text = t->AsEnumType()->Lookup(z.AsInt()); - strcpy(res, text); - res += strlen(text); - break; + case TYPE_ENUM: + text = t->AsEnumType()->Lookup(z.AsInt()); + strcpy(res, text); + res += strlen(text); + break; - TYPE_PORT: - { - uint32_t full_p = static_cast(z.AsCount()); - zeek_uint_t p = full_p & ~PORT_SPACE_MASK; - n = modp_ulitoa10(p, res); - res += n; - - if ( (full_p & TCP_PORT_MASK) == TCP_PORT_MASK ) + case TYPE_PORT: { - strcpy(res, "/tcp"); - res += 4; + uint32_t full_p = static_cast(z.AsCount()); + zeek_uint_t p = full_p & ~PORT_SPACE_MASK; + n = modp_ulitoa10(p, res); + res += n; + + if ( (full_p & TCP_PORT_MASK) == TCP_PORT_MASK ) + { + strcpy(res, "/tcp"); + res += 4; + } + + else if ( (full_p & UDP_PORT_MASK) == UDP_PORT_MASK ) + { + strcpy(res, "/udp"); + res += 4; + } + + else if ( (full_p & ICMP_PORT_MASK) == ICMP_PORT_MASK ) + { + strcpy(res, "/icmp"); + res += 5; + } + + else + { + strcpy(res, "/unknown"); + res += 8; + } + + break; } - else if ( (full_p & UDP_PORT_MASK) == UDP_PORT_MASK ) - { - strcpy(res, "/udp"); - res += 4; - } + case TYPE_ADDR: + str = z.AsAddr()->Get().AsString(); + strcpy(res, str.c_str()); + res += strlen(str.c_str()); + break; - else if ( (full_p & ICMP_PORT_MASK) == ICMP_PORT_MASK ) - { - strcpy(res, "/icmp"); - res += 5; - } - - else - { - strcpy(res, "/unknown"); - res += 8; - } - - break; - } - - TYPE_ADDR: - str = z.AsAddr()->Get().AsString(); - strcpy(res, str.c_str()); - res += strlen(str.c_str()); - break; - - TYPE_SUBNET: - str = z.AsSubNet()->Get().AsString(); - strcpy(res, str.c_str()); - res += strlen(str.c_str()); - break; + case TYPE_SUBNET: + str = z.AsSubNet()->Get().AsString(); + strcpy(res, str.c_str()); + res += strlen(str.c_str()); + break; default: reporter->InternalError("bad type in FixedCatArg::RenderInto"); diff --git a/src/script_opt/ZAM/BuiltInSupport.h b/src/script_opt/ZAM/BuiltInSupport.h index a3193eaa89..9fbf6f1b1d 100644 --- a/src/script_opt/ZAM/BuiltInSupport.h +++ b/src/script_opt/ZAM/BuiltInSupport.h @@ -88,7 +88,7 @@ public: protected: size_t ComputeMaxSize(ZVal* zframe, int slot) override; - const char* text; + const char* text = nullptr; size_t n = 0; };