aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-11-15 02:46:25 +0800
committerGitHub <noreply@github.com>2016-11-15 02:46:25 +0800
commit07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2 (patch)
treee68a5f8b3869fd5d32e1e6c623f701c385ed4461
parent54555adb67f098161780cbc266b54eead9fe7b8a (diff)
parentdbcbfafda8e44f56a7952993fd9f6699822395d6 (diff)
downloaddexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.tar
dexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.tar.gz
dexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.tar.bz2
dexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.tar.lz
dexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.tar.xz
dexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.tar.zst
dexon-solidity-07e4cd6e3230d42d974f2b3a1688f74f0b9fe8e2.zip
Merge pull request #1372 from ethereum/invalid_enum_as_external_ret
Invalid enum as external ret
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp4
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp34
2 files changed, 36 insertions, 2 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 54645289..db4aac34 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -315,7 +315,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
Type::Category stackTypeCategory = _typeOnStack.category();
Type::Category targetTypeCategory = _targetType.category();
- bool enumOverflowCheckPending = (targetTypeCategory == Type::Category::Enum);
+ bool enumOverflowCheckPending = (targetTypeCategory == Type::Category::Enum || stackTypeCategory == Type::Category::Enum);
switch (stackTypeCategory)
{
@@ -353,7 +353,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
solAssert(_targetType == _typeOnStack || targetTypeCategory == Type::Category::Integer, "");
if (enumOverflowCheckPending)
{
- EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType);
+ EnumType const& enumType = dynamic_cast<decltype(enumType)>(_typeOnStack);
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());
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 5582e4a1..74cf53cf 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -4499,6 +4499,40 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls)
BOOST_CHECK(callContractFunction("t2()") == encodeArgs(u256(9)));
}
+BOOST_AUTO_TEST_CASE(invalid_enum_as_external_ret)
+{
+ char const* sourceCode = R"(
+ contract C {
+ enum X { A, B }
+
+ function test_return() returns (X) {
+ X garbled;
+ assembly {
+ garbled := 5
+ }
+ return garbled;
+ }
+ function test_inline_assignment() returns (X _ret) {
+ assembly {
+ _ret := 5
+ }
+ }
+ function test_assignment() returns (X _ret) {
+ X tmp;
+ assembly {
+ tmp := 5
+ }
+ _ret = tmp;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ // both should throw
+ BOOST_CHECK(callContractFunction("test_return()") == encodeArgs());
+ BOOST_CHECK(callContractFunction("test_inline_assignment()") == encodeArgs());
+ BOOST_CHECK(callContractFunction("test_assignment()") == encodeArgs());
+}
+
BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes)
{
// bug #1798