aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-24 06:23:10 +0800
committerchriseth <c@ethdev.com>2015-06-24 06:23:46 +0800
commit2d169748b7b80079d78c0197a773bebd46189175 (patch)
treeca588f8c73fc67bc7c5947f44eb2a79bc301d3e0
parentfd1a01bbce5b5b6491e05b87fb183a55e9804f4e (diff)
downloaddexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.tar
dexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.tar.gz
dexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.tar.bz2
dexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.tar.lz
dexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.tar.xz
dexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.tar.zst
dexon-solidity-2d169748b7b80079d78c0197a773bebd46189175.zip
Copy only expected arguments for constructor if statically sized.
-rw-r--r--Compiler.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/Compiler.cpp b/Compiler.cpp
index 68052e27..f5570b98 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -165,10 +165,26 @@ void Compiler::appendConstructor(FunctionDefinition const& _constructor)
// copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
if (!_constructor.getParameters().empty())
{
+ unsigned argumentSize = 0;
+ for (ASTPointer<VariableDeclaration> const& var: _constructor.getParameters())
+ if (var->getType()->isDynamicallySized())
+ {
+ argumentSize = 0;
+ break;
+ }
+ else
+ argumentSize += var->getType()->getCalldataEncodedSize();
+
CompilerUtils(m_context).fetchFreeMemoryPointer();
- m_context.appendProgramSize(); // program itself
- // CODESIZE is program plus manually added arguments
- m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB;
+ if (argumentSize == 0)
+ {
+ // argument size is dynamic, use CODESIZE to determine it
+ m_context.appendProgramSize(); // program itself
+ // CODESIZE is program plus manually added arguments
+ m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB;
+ }
+ else
+ m_context << u256(argumentSize);
// stack: <memptr> <argument size>
m_context << eth::Instruction::DUP1;
m_context.appendProgramSize();