mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1633 from ethereum/negative-length-arrays
Reject negative length arrays
This commit is contained in:
commit
b3b82c46e7
@ -3,6 +3,9 @@
|
||||
Features:
|
||||
* Type system: Support explicit conversion of external function to address.
|
||||
|
||||
Bugfixes:
|
||||
* Type system: Disallow arrays with negative length.
|
||||
|
||||
### 0.4.9 (2017-01-31)
|
||||
|
||||
Features:
|
||||
|
@ -130,6 +130,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
|
||||
auto const* lengthType = dynamic_cast<RationalNumberType const*>(length->annotation().type.get());
|
||||
if (!lengthType || lengthType->isFractional())
|
||||
fatalTypeError(length->location(), "Invalid array length, expected integer literal.");
|
||||
else if (lengthType->isNegative())
|
||||
fatalTypeError(length->location(), "Array with negative length specified.");
|
||||
else
|
||||
_typeName.annotation().type = make_shared<ArrayType>(DataLocation::Storage, baseType, lengthType->literalValue(nullptr));
|
||||
}
|
||||
|
@ -411,6 +411,9 @@ public:
|
||||
/// @returns true if the value is not an integer.
|
||||
bool isFractional() const { return m_value.denominator() != 1; }
|
||||
|
||||
/// @returns true if the value is negative.
|
||||
bool isNegative() const { return m_value < 0; }
|
||||
|
||||
private:
|
||||
rational m_value;
|
||||
};
|
||||
|
@ -1919,6 +1919,16 @@ BOOST_AUTO_TEST_CASE(array_with_nonconstant_length)
|
||||
CHECK_ERROR(text, TypeError, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(array_with_negative_length)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract c {
|
||||
function f(uint a) { uint8[-1] x; }
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "Array with negative length specified");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(array_copy_with_different_types1)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user