aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-10-11 18:28:21 +0800
committerchriseth <chris@ethereum.org>2017-10-17 04:29:31 +0800
commit6001bd1406e7adbb6607485afb775bbb5b6c2ac3 (patch)
tree7f5151acaf7e12f9b12818cfd20a95bf24f53849 /libsolidity/codegen
parent7989fc4c356929de47e2d696ef5478c398941508 (diff)
downloaddexon-solidity-6001bd1406e7adbb6607485afb775bbb5b6c2ac3.tar.gz
dexon-solidity-6001bd1406e7adbb6607485afb775bbb5b6c2ac3.tar.zst
dexon-solidity-6001bd1406e7adbb6607485afb775bbb5b6c2ac3.zip
Allocate one byte per memory byte array element instead of 32.
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index fe37baac..bb8c4a94 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -858,8 +858,15 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
m_context << Instruction::DUP1 << Instruction::DUP3 << Instruction::MSTORE;
// Stack: memptr requested_length
// update free memory pointer
- m_context << Instruction::DUP1 << arrayType.baseType()->memoryHeadSize();
- m_context << Instruction::MUL << u256(32) << Instruction::ADD;
+ m_context << Instruction::DUP1;
+ // Stack: memptr requested_length requested_length
+ if (arrayType.isByteArray())
+ // Round up to multiple of 32
+ m_context << u256(31) << Instruction::ADD << u256(31) << Instruction::NOT << Instruction::AND;
+ else
+ m_context << arrayType.baseType()->memoryHeadSize() << Instruction::MUL;
+ // stacK: memptr requested_length data_size
+ m_context << u256(32) << Instruction::ADD;
m_context << Instruction::DUP3 << Instruction::ADD;
utils().storeFreeMemoryPointer();
// Stack: memptr requested_length