Fix reported packed encoded size for arrays and structs.

This commit is contained in:
chriseth 2019-01-22 12:30:46 +01:00
parent ea292393a3
commit e3791d6dcf
2 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,9 @@
### 0.5.4 (unreleased)
Bugfixes:
* Type system: Properly report packed encoded size for arrays and structs (mostly unused until now).
Language Features:

View File

@ -1716,8 +1716,10 @@ bigint ArrayType::unlimitedCalldataEncodedSize(bool _padded) const
{
if (isDynamicallySized())
return 32;
bigint size = bigint(length()) * (isByteArray() ? 1 : baseType()->calldataEncodedSize(_padded));
size = ((size + 31) / 32) * 32;
// Array elements are always padded.
bigint size = bigint(length()) * (isByteArray() ? 1 : baseType()->calldataEncodedSize(true));
if (_padded)
size = ((size + 31) / 32) * 32;
return size;
}
@ -2034,7 +2036,7 @@ bool StructType::operator==(Type const& _other) const
return ReferenceType::operator==(other) && other.m_struct == m_struct;
}
unsigned StructType::calldataEncodedSize(bool _padded) const
unsigned StructType::calldataEncodedSize(bool) const
{
unsigned size = 0;
for (auto const& member: members(nullptr))
@ -2042,7 +2044,8 @@ unsigned StructType::calldataEncodedSize(bool _padded) const
return 0;
else
{
unsigned memberSize = member.type->calldataEncodedSize(_padded);
// Struct members are always padded.
unsigned memberSize = member.type->calldataEncodedSize(true);
if (memberSize == 0)
return 0;
size += memberSize;