mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Issue error properly for oversized arrays for calldata
This commit is contained in:
@@ -1395,12 +1395,23 @@ bool ArrayType::operator==(Type const& _other) const
|
||||
return isDynamicallySized() || length() == other.length();
|
||||
}
|
||||
|
||||
unsigned ArrayType::calldataEncodedSize(bool _padded) const
|
||||
bool ArrayType::validForCalldata() const
|
||||
{
|
||||
return unlimitedCalldataEncodedSize(true) <= numeric_limits<unsigned>::max();
|
||||
}
|
||||
|
||||
bigint ArrayType::unlimitedCalldataEncodedSize(bool _padded) const
|
||||
{
|
||||
if (isDynamicallySized())
|
||||
return 32;
|
||||
bigint size = bigint(length()) * (isByteArray() ? 1 : baseType()->calldataEncodedSize(_padded));
|
||||
size = ((size + 31) / 32) * 32;
|
||||
return size;
|
||||
}
|
||||
|
||||
unsigned ArrayType::calldataEncodedSize(bool _padded) const
|
||||
{
|
||||
bigint size = unlimitedCalldataEncodedSize(_padded);
|
||||
solAssert(size <= numeric_limits<unsigned>::max(), "Array size does not fit unsigned.");
|
||||
return unsigned(size);
|
||||
}
|
||||
|
||||
@@ -616,6 +616,9 @@ public:
|
||||
virtual TypePointer interfaceType(bool _inLibrary) const override;
|
||||
virtual bool canBeUsedExternally(bool _inLibrary) const override;
|
||||
|
||||
/// @returns true if this is valid to be stored in calldata
|
||||
bool validForCalldata() const;
|
||||
|
||||
/// @returns true if this is a byte array or a string
|
||||
bool isByteArray() const { return m_arrayKind != ArrayKind::Ordinary; }
|
||||
/// @returns true if this is a string
|
||||
@@ -630,6 +633,8 @@ private:
|
||||
/// String is interpreted as a subtype of Bytes.
|
||||
enum class ArrayKind { Ordinary, Bytes, String };
|
||||
|
||||
bigint unlimitedCalldataEncodedSize(bool _padded) const;
|
||||
|
||||
///< Byte arrays ("bytes") and strings have different semantics from ordinary arrays.
|
||||
ArrayKind m_arrayKind = ArrayKind::Ordinary;
|
||||
TypePointer m_baseType;
|
||||
|
||||
Reference in New Issue
Block a user