mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 07:38:19 +00:00
Fix some Coverity issues in the recent ZAM updates
This commit is contained in:
parent
20226f084b
commit
157a859104
3 changed files with 117 additions and 117 deletions
|
@ -313,25 +313,25 @@ ZInstAux* ZAMCompiler::BuildCatAux(const ExprPList& args)
|
||||||
|
|
||||||
switch ( t->Tag() )
|
switch ( t->Tag() )
|
||||||
{
|
{
|
||||||
TYPE_BOOL:
|
case TYPE_BOOL:
|
||||||
TYPE_INT:
|
case TYPE_INT:
|
||||||
TYPE_COUNT:
|
case TYPE_COUNT:
|
||||||
TYPE_DOUBLE:
|
case TYPE_DOUBLE:
|
||||||
TYPE_TIME:
|
case TYPE_TIME:
|
||||||
TYPE_ENUM:
|
case TYPE_ENUM:
|
||||||
TYPE_PORT:
|
case TYPE_PORT:
|
||||||
TYPE_ADDR:
|
case TYPE_ADDR:
|
||||||
TYPE_SUBNET:
|
case TYPE_SUBNET:
|
||||||
ca = std::make_unique<FixedCatArg>(t);
|
ca = std::make_unique<FixedCatArg>(t);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_STRING:
|
case TYPE_STRING:
|
||||||
ca = std::make_unique<StringCatArg>();
|
ca = std::make_unique<StringCatArg>();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_PATTERN:
|
case TYPE_PATTERN:
|
||||||
ca = std::make_unique<PatternCatArg>();
|
ca = std::make_unique<PatternCatArg>();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ca = std::make_unique<DescCatArg>(t);
|
ca = std::make_unique<DescCatArg>(t);
|
||||||
|
|
|
@ -12,43 +12,43 @@ FixedCatArg::FixedCatArg(const TypePtr& _t) : t(_t)
|
||||||
{
|
{
|
||||||
switch ( t->Tag() )
|
switch ( t->Tag() )
|
||||||
{
|
{
|
||||||
TYPE_BOOL:
|
case TYPE_BOOL:
|
||||||
max_size = 1;
|
max_size = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_INT:
|
case TYPE_INT:
|
||||||
max_size = 20; // sufficient for 64 bits
|
max_size = 20; // sufficient for 64 bits
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_COUNT:
|
case TYPE_COUNT:
|
||||||
max_size = 20; // sufficient for 64 bits
|
max_size = 20; // sufficient for 64 bits
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_DOUBLE:
|
case TYPE_DOUBLE:
|
||||||
TYPE_TIME:
|
case TYPE_TIME:
|
||||||
max_size = 32; // from modp_dtoa2 documentatino
|
max_size = 32; // from modp_dtoa2 documentatino
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_ENUM:
|
case TYPE_ENUM:
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
for ( auto e : t->AsEnumType()->Names() )
|
for ( const auto& e : t->AsEnumType()->Names() )
|
||||||
n += e.first.size();
|
n += e.first.size();
|
||||||
max_size = n;
|
max_size = n;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPE_PORT:
|
case TYPE_PORT:
|
||||||
max_size = 5 + 1 + 7; // <number> + / + "unknown
|
max_size = 5 + 1 + 7; // <number> + / + "unknown
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_ADDR:
|
case TYPE_ADDR:
|
||||||
max_size = 39; // for IPv6
|
max_size = 39; // for IPv6
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_SUBNET:
|
case TYPE_SUBNET:
|
||||||
max_size = 39 + 1 + 3; // for IPv6 + / + <3-digits>
|
max_size = 39 + 1 + 3; // for IPv6 + / + <3-digits>
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reporter->InternalError("bad type in FixedCatArg constructor");
|
reporter->InternalError("bad type in FixedCatArg constructor");
|
||||||
|
@ -64,85 +64,85 @@ void FixedCatArg::RenderInto(ZVal* zframe, int slot, char*& res)
|
||||||
|
|
||||||
switch ( t->Tag() )
|
switch ( t->Tag() )
|
||||||
{
|
{
|
||||||
TYPE_BOOL:
|
case TYPE_BOOL:
|
||||||
*(res++) = z.AsInt() ? 'T' : 'F';
|
*(res++) = z.AsInt() ? 'T' : 'F';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_INT:
|
case TYPE_INT:
|
||||||
n = modp_litoa10(z.AsInt(), res);
|
n = modp_litoa10(z.AsInt(), res);
|
||||||
res += n;
|
res += n;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_COUNT:
|
case TYPE_COUNT:
|
||||||
n = modp_ulitoa10(z.AsCount(), res);
|
n = modp_ulitoa10(z.AsCount(), res);
|
||||||
res += n;
|
res += n;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_DOUBLE:
|
case TYPE_DOUBLE:
|
||||||
TYPE_TIME:
|
case TYPE_TIME:
|
||||||
n = modp_dtoa2(z.AsDouble(), res, 6);
|
n = modp_dtoa2(z.AsDouble(), res, 6);
|
||||||
res += n;
|
res += n;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_PATTERN:
|
case TYPE_PATTERN:
|
||||||
text = z.AsPattern()->AsPattern()->PatternText();
|
text = z.AsPattern()->AsPattern()->PatternText();
|
||||||
*(res++) = '/';
|
*(res++) = '/';
|
||||||
strcpy(res, text);
|
strcpy(res, text);
|
||||||
res += strlen(text);
|
res += strlen(text);
|
||||||
*(res++) = '/';
|
*(res++) = '/';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_ENUM:
|
case TYPE_ENUM:
|
||||||
text = t->AsEnumType()->Lookup(z.AsInt());
|
text = t->AsEnumType()->Lookup(z.AsInt());
|
||||||
strcpy(res, text);
|
strcpy(res, text);
|
||||||
res += strlen(text);
|
res += strlen(text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TYPE_PORT:
|
case TYPE_PORT:
|
||||||
{
|
|
||||||
uint32_t full_p = static_cast<uint32_t>(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");
|
uint32_t full_p = static_cast<uint32_t>(z.AsCount());
|
||||||
res += 4;
|
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 )
|
case TYPE_ADDR:
|
||||||
{
|
str = z.AsAddr()->Get().AsString();
|
||||||
strcpy(res, "/udp");
|
strcpy(res, str.c_str());
|
||||||
res += 4;
|
res += strlen(str.c_str());
|
||||||
}
|
break;
|
||||||
|
|
||||||
else if ( (full_p & ICMP_PORT_MASK) == ICMP_PORT_MASK )
|
case TYPE_SUBNET:
|
||||||
{
|
str = z.AsSubNet()->Get().AsString();
|
||||||
strcpy(res, "/icmp");
|
strcpy(res, str.c_str());
|
||||||
res += 5;
|
res += strlen(str.c_str());
|
||||||
}
|
break;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reporter->InternalError("bad type in FixedCatArg::RenderInto");
|
reporter->InternalError("bad type in FixedCatArg::RenderInto");
|
||||||
|
|
|
@ -88,7 +88,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
size_t ComputeMaxSize(ZVal* zframe, int slot) override;
|
size_t ComputeMaxSize(ZVal* zframe, int slot) override;
|
||||||
|
|
||||||
const char* text;
|
const char* text = nullptr;
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue