aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/CompilerUtils.cpp
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-11-08 20:37:59 +0800
committerYoichi Hirai <i@yoichihirai.com>2016-11-12 00:48:03 +0800
commit98dcd883e4ee1b3d62a1b9e7d4e5d4e038ea0434 (patch)
tree4bf7151af69100652b42cf989d1451e6e41d128e /libsolidity/codegen/CompilerUtils.cpp
parent8856adce8f1829cecf7353c64c8cf07058da6f4f (diff)
downloaddexon-solidity-98dcd883e4ee1b3d62a1b9e7d4e5d4e038ea0434.tar.gz
dexon-solidity-98dcd883e4ee1b3d62a1b9e7d4e5d4e038ea0434.tar.zst
dexon-solidity-98dcd883e4ee1b3d62a1b9e7d4e5d4e038ea0434.zip
codegen: check the value range after converting something to an enum element
Diffstat (limited to 'libsolidity/codegen/CompilerUtils.cpp')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index e064c1a6..5e045996 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -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)