From 0a6c937dcbb3671e2fa5f6d7b50b5a909cf522d0 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 9 Nov 2016 14:14:18 +0100 Subject: codegen: shorten the overflow checking when converting into enums --- libsolidity/codegen/CompilerUtils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libsolidity') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 5e045996..ad155b13 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -661,7 +661,8 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp if (targetTypeCategory == Type::Category::Enum) { EnumType const& enumType = dynamic_cast(_targetType); - m_context << u256(enumType.numberOfMembers()) << Instruction::DUP2 << Instruction::LT << Instruction::ISZERO; + solAssert(enumType.numberOfMembers() > 0, "empty enum should have caused a parser error."); + m_context << u256(enumType.numberOfMembers() - 1) << Instruction::DUP2 << Instruction::GT; m_context.appendConditionalJumpTo(m_context.errorTag()); } } -- cgit