From c2caa9e6a156e44e180e876906c3b24834f6a523 Mon Sep 17 00:00:00 2001 From: Evan Typanski Date: Tue, 17 Sep 2024 10:41:21 -0400 Subject: [PATCH] Switch some internal enum values to unsigned --- src/CompHash.cc | 6 +++--- src/Type.cc | 6 ++++++ src/Type.h | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index aef744ee9d..dac6ebd7e6 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -142,9 +142,7 @@ bool CompositeHash::RecoverOneVal(const HashKey& hk, Type* t, ValPtr* pval, bool zeek_int_t i; hk.Read("int", i); - if ( tag == TYPE_ENUM ) - *pval = t->AsEnumType()->GetEnumVal(i); - else if ( tag == TYPE_BOOL ) + if ( tag == TYPE_BOOL ) *pval = val_mgr->Bool(i); else if ( tag == TYPE_INT ) *pval = val_mgr->Int(i); @@ -164,6 +162,8 @@ bool CompositeHash::RecoverOneVal(const HashKey& hk, Type* t, ValPtr* pval, bool case TYPE_PORT: *pval = val_mgr->Port(u); break; + case TYPE_ENUM: *pval = t->AsEnumType()->GetEnumVal(static_cast(u)); break; + default: reporter->InternalError("bad internal unsigned int in CompositeHash::RecoverOneVal()"); *pval = nullptr; diff --git a/src/Type.cc b/src/Type.cc index fe58ffbbeb..eed39209b2 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1548,6 +1548,12 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek return; } + if ( val > std::numeric_limits<::zeek_int_t>::max() ) { + reporter->Error("enumerator value cannot be greater than max int"); + SetError(); + return; + } + auto fullname = detail::make_full_var_name(module_name.c_str(), name); auto id = id::find(fullname); diff --git a/src/Type.h b/src/Type.h index f8c9e385f7..2d9a5c565f 100644 --- a/src/Type.h +++ b/src/Type.h @@ -110,11 +110,11 @@ constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept { case TYPE_VOID: return TYPE_INTERNAL_VOID; case TYPE_BOOL: - case TYPE_INT: - case TYPE_ENUM: return TYPE_INTERNAL_INT; + case TYPE_INT: return TYPE_INTERNAL_INT; case TYPE_COUNT: - case TYPE_PORT: return TYPE_INTERNAL_UNSIGNED; + case TYPE_PORT: + case TYPE_ENUM: return TYPE_INTERNAL_UNSIGNED; case TYPE_DOUBLE: case TYPE_TIME: