mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change ABIEncoderV1 to not pad empty strings
This commit is contained in:
@@ -531,10 +531,15 @@ void CompilerUtils::encodeToMemory(
|
||||
if (_givenTypes[i]->category() == Type::Category::StringLiteral)
|
||||
{
|
||||
auto const& strType = dynamic_cast<StringLiteralType const&>(*_givenTypes[i]);
|
||||
m_context << u256(strType.value().size());
|
||||
auto const size = strType.value().size();
|
||||
m_context << u256(size);
|
||||
storeInMemoryDynamic(*TypeProvider::uint256(), true);
|
||||
// stack: ... <end_of_mem'>
|
||||
storeInMemoryDynamic(strType, _padToWordBoundaries);
|
||||
|
||||
// Do not output empty padding for zero-length strings.
|
||||
// TODO: handle this in storeInMemoryDynamic
|
||||
if (size != 0)
|
||||
storeInMemoryDynamic(strType, _padToWordBoundaries);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -104,12 +104,13 @@ public:
|
||||
/// Stores a 256 bit integer from stack in memory.
|
||||
/// @param _offset offset in memory
|
||||
void storeInMemory(unsigned _offset);
|
||||
|
||||
/// Dynamic version of @see storeInMemory, expects the memory offset below the value on the stack
|
||||
/// and also updates that. For reference types, only copies the data pointer. Fails for
|
||||
/// non-memory-references.
|
||||
/// non-memory-references. For string literals no value is available on the stack.
|
||||
/// @param _padToWords if true, adds zeros to pad to multiple of 32 bytes. Array elements
|
||||
/// are always padded (except for byte arrays), regardless of this parameter.
|
||||
/// @param _cleanup if true, adds code to cleanup the value before storing it.
|
||||
/// are always padded (except for byte arrays), regardless of this parameter.
|
||||
/// Stack pre: memory_offset value...
|
||||
/// Stack post: (memory_offset+length)
|
||||
void storeInMemoryDynamic(Type const& _type, bool _padToWords = true, bool _cleanup = true);
|
||||
|
||||
Reference in New Issue
Block a user