aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLianaHus <liana@ethdev.com>2015-09-23 23:26:52 +0800
committerLianaHus <liana@ethdev.com>2015-09-23 23:31:47 +0800
commitc096c3c3490176c8fa61345a38b14078a399962f (patch)
tree93c0d7c98daf8345bb2d2572fc0ce1cbdda856bb
parent5ba559beafc5f84a50f148227a2c660c8f8bc488 (diff)
downloaddexon-solidity-c096c3c3490176c8fa61345a38b14078a399962f.tar.gz
dexon-solidity-c096c3c3490176c8fa61345a38b14078a399962f.tar.zst
dexon-solidity-c096c3c3490176c8fa61345a38b14078a399962f.zip
improved the test
-rw-r--r--libsolidity/Types.cpp5
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp16
2 files changed, 16 insertions, 5 deletions
diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp
index 43120ce5..18f2817e 100644
--- a/libsolidity/Types.cpp
+++ b/libsolidity/Types.cpp
@@ -857,8 +857,9 @@ u256 ArrayType::memorySize() const
{
solAssert(!isDynamicallySized(), "");
solAssert(m_location == DataLocation::Memory, "");
-
- return m_length * m_baseType->memoryHeadSize();
+ u256 size = m_length * m_baseType->memoryHeadSize();
+ solAssert(size <= numeric_limits<unsigned>::max(), "Array size does not fit unsigned.");
+ return size;
}
TypePointer ArrayType::copyForLocation(DataLocation _location, bool _isPointer) const
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 42dfcd37..3124f9cf 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5329,19 +5329,29 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type)
{
char const* sourceCode = R"(
contract A {
- function f() constant returns (uint16[5] arr)
+ function f(uint16 input) constant returns (uint16[5] arr)
{
+ arr[0] = input;
+ arr[1] = ++input;
+ arr[2] = ++input;
+ arr[3] = ++input;
+ arr[4] = ++input;
}
}
contract B {
- function f()
+ function f() returns (uint16[5] res, uint16[5] res2)
{
var a = new A();
- uint16[5] memory res = a.f();
+ res = a.f(2);
+ res2 = a.f(1000);
}
}
)";
compileAndRun(sourceCode, 0, "B");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(
+ u256(2), u256(3), u256(4), u256(5), u256(6), // first return argument
+ u256(1000), u256(1001), u256(1002), u256(1003), u256(1004)) // second return argument
+ );
}
BOOST_AUTO_TEST_SUITE_END()