mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
codegen: check the value range after converting something to an enum element
This commit is contained in:
@@ -656,6 +656,14 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
|
||||
solAssert(_typeOnStack == _targetType, "Invalid type conversion requested.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check the conversion result fits in a range.
|
||||
if (targetTypeCategory == Type::Category::Enum)
|
||||
{
|
||||
EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType);
|
||||
m_context << u256(enumType.numberOfMembers()) << Instruction::DUP2 << Instruction::LT << Instruction::ISZERO;
|
||||
m_context.appendConditionalJumpTo(m_context.errorTag());
|
||||
}
|
||||
}
|
||||
|
||||
void CompilerUtils::pushZeroValue(Type const& _type)
|
||||
|
||||
Reference in New Issue
Block a user