Fix port/enum values SizeOf not being a count

Really, they both should be count. But, they were getting provided as an
integer. Port is easy since it is backed by an unsigned value. Enums
*should* be unsigned, but aren't. This doesn't address that, it just
takes the other name for this operator (absolute value) and makes the
enum value positive if it's negative.

This fixes a case where using the size of operator on enum/port values
in certain contexts (like the default parameter of a struct) would cause
an internal error.
This commit is contained in:
Evan Typanski 2024-09-17 10:55:45 -04:00
parent ba91de59b0
commit d3dd8a155d
4 changed files with 29 additions and 3 deletions

View file

@ -594,7 +594,7 @@ void IntervalVal::ValDescribe(ODesc* d) const {
}
}
ValPtr PortVal::SizeVal() const { return val_mgr->Int(uint_val); }
ValPtr PortVal::SizeVal() const { return val_mgr->Count(uint_val); }
uint32_t PortVal::Mask(uint32_t port_num, TransportProto port_type) {
// Note, for ICMP one-way connections:
@ -3133,7 +3133,15 @@ unsigned int RecordVal::ComputeFootprint(std::unordered_set<const Val*>* analyze
return fp;
}
ValPtr EnumVal::SizeVal() const { return val_mgr->Int(AsInt()); }
ValPtr EnumVal::SizeVal() const {
// Negative enums are rejected at parse time, but not internally. Handle the
// negative case just like a signed integer, as that is an enum's underlying
// type.
if ( AsInt() < 0 )
return val_mgr->Count(-AsInt());
else
return val_mgr->Count(AsInt());
}
void EnumVal::ValDescribe(ODesc* d) const {
const char* ename = type->AsEnumType()->Lookup(int_val);