mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Bugfix for constructor unpacking with fixed-size arrays.
This commit is contained in:
parent
c806b9bcdb
commit
6796afc2f8
@ -305,11 +305,19 @@ void Compiler::appendCalldataUnpacker(TypePointers const& _typeParameters, bool
|
|||||||
// @todo If base type is an array or struct, it is still calldata-style encoded, so
|
// @todo If base type is an array or struct, it is still calldata-style encoded, so
|
||||||
// we would have to convert it like below.
|
// we would have to convert it like below.
|
||||||
solAssert(arrayType.location() == DataLocation::Memory, "");
|
solAssert(arrayType.location() == DataLocation::Memory, "");
|
||||||
// compute data pointer
|
if (arrayType.isDynamicallySized())
|
||||||
m_context << eth::Instruction::DUP1 << eth::Instruction::MLOAD;
|
{
|
||||||
m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
|
// compute data pointer
|
||||||
m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
|
m_context << eth::Instruction::DUP1 << eth::Instruction::MLOAD;
|
||||||
m_context << u256(0x20) << eth::Instruction::ADD;
|
m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
|
||||||
|
m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
|
||||||
|
m_context << u256(0x20) << eth::Instruction::ADD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_context << eth::Instruction::DUP1;
|
||||||
|
m_context << u256(arrayType.calldataEncodedSize(true)) << eth::Instruction::ADD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4671,6 +4671,23 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract Creator {
|
||||||
|
uint public r;
|
||||||
|
address public ch;
|
||||||
|
function Creator(address[3] s, uint x) {
|
||||||
|
r = x;
|
||||||
|
ch = s[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "Creator", encodeArgs(u256(1), u256(2), u256(3), u256(4)));
|
||||||
|
BOOST_REQUIRE(callContractFunction("r()") == encodeArgs(u256(4)));
|
||||||
|
BOOST_REQUIRE(callContractFunction("ch()") == encodeArgs(u256(3)));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage)
|
BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user