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:
parent
8856adce8f
commit
98dcd883e4
@ -3,6 +3,7 @@
|
||||
Features:
|
||||
* Do-while loops: support for a C-style do{<block>}while(<expr>); control structure
|
||||
* Type checker: now more eagerly searches for a common type of an inline array with mixed types
|
||||
* Code generator: generates a runtime error when an out-of-range value is converted into an enum type.
|
||||
|
||||
### 0.4.4 (2016-10-31)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user