codegen: check the value range after converting something to an enum element

This commit is contained in:
Yoichi Hirai
2016-11-11 17:48:03 +01:00
parent 8856adce8f
commit 98dcd883e4
2 changed files with 9 additions and 0 deletions
+8
View File
@@ -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)