aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp4
-rw-r--r--libsolidity/codegen/CompilerUtils.h1
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp9
3 files changed, 9 insertions, 5 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index efb9b10a..d7d17b8e 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -288,8 +288,8 @@ void CompilerUtils::memoryCopy()
m_context << u256(0) << u256(identityContractAddress);
// compute gas costs
m_context << u256(32) << Instruction::DUP5 << u256(31) << Instruction::ADD;
- static unsigned c_identityGas = 3;
- static unsigned c_identityWordGas = 15;
+ static unsigned c_identityGas = 15;
+ static unsigned c_identityWordGas = 3;
m_context << Instruction::DIV << u256(c_identityWordGas) << Instruction::MUL;
m_context << u256(c_identityGas) << Instruction::ADD;
m_context << Instruction::CALL;
diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h
index 55254013..da74dc90 100644
--- a/libsolidity/codegen/CompilerUtils.h
+++ b/libsolidity/codegen/CompilerUtils.h
@@ -104,6 +104,7 @@ public:
);
/// Zero-initialises (the data part of) an already allocated memory array.
+ /// Length has to be nonzero!
/// Stack pre: <length> <memptr>
/// Stack post: <updated_memptr>
void zeroInitialiseMemoryArray(ArrayType const& _type);
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index b973a117..80009a90 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -792,15 +792,18 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
utils().storeFreeMemoryPointer();
// Stack: memptr requested_length
+ // Check if length is zero
+ m_context << Instruction::DUP1 << Instruction::ISZERO;
+ auto skipInit = m_context.appendConditionalJump();
+
// We only have to initialise if the base type is a not a value type.
if (dynamic_cast<ReferenceType const*>(arrayType.baseType().get()))
{
m_context << Instruction::DUP2 << u256(32) << Instruction::ADD;
utils().zeroInitialiseMemoryArray(arrayType);
- m_context << Instruction::POP;
}
- else
- m_context << Instruction::POP;
+ m_context << skipInit;
+ m_context << Instruction::POP;
break;
}
default: