mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5137 from ethereum/fix_5052
Fixes #5052 (very large hex literals wrongly interpreted)
This commit is contained in:
commit
7dbe880173
@ -841,13 +841,8 @@ TypePointer RationalNumberType::forLiteral(Literal const& _literal)
|
|||||||
TypePointer compatibleBytesType;
|
TypePointer compatibleBytesType;
|
||||||
if (_literal.isHexNumber())
|
if (_literal.isHexNumber())
|
||||||
{
|
{
|
||||||
size_t digitCount = count_if(
|
size_t const digitCount = _literal.valueWithoutUnderscores().length() - 2;
|
||||||
_literal.value().begin() + 2, // skip "0x"
|
if (digitCount % 2 == 0 && (digitCount / 2) <= 32)
|
||||||
_literal.value().end(),
|
|
||||||
[](unsigned char _c) -> bool { return isxdigit(_c); }
|
|
||||||
);
|
|
||||||
// require even number of digits
|
|
||||||
if (!(digitCount & 1))
|
|
||||||
compatibleBytesType = make_shared<FixedBytesType>(digitCount / 2);
|
compatibleBytesType = make_shared<FixedBytesType>(digitCount / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,8 +856,7 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal
|
|||||||
rational value;
|
rational value;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ASTString valueString = _literal.value();
|
ASTString valueString = _literal.valueWithoutUnderscores();
|
||||||
boost::erase_all(valueString, "_");// Remove underscore separators
|
|
||||||
|
|
||||||
auto expPoint = find(valueString.begin(), valueString.end(), 'e');
|
auto expPoint = find(valueString.begin(), valueString.end(), 'e');
|
||||||
if (expPoint == valueString.end())
|
if (expPoint == valueString.end())
|
||||||
|
10
test/libsolidity/syntaxTests/types/rational_number_huge.sol
Normal file
10
test/libsolidity/syntaxTests/types/rational_number_huge.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
contract C {
|
||||||
|
function f(uint y) public pure {
|
||||||
|
// fits FixedBytes with exactly 32-bytes
|
||||||
|
y = 0xffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000; // FixedBytes (32)
|
||||||
|
|
||||||
|
// fits exactly into FixedBytes (32), ensures underscored literals won't hurt
|
||||||
|
y = 0xffffffff00000000ffffffff00000000ffffffff00000000ffffffff_00000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
function f(uint y) public pure {
|
||||||
|
// one byte too long for storing in Fixedbytes (would require 33 bytes)
|
||||||
|
y = 0xffffffff00000000ffffffff00000000ffffffff00000000ffffffff000000001;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (142-209): Type int_const 1852...(71 digits omitted)...7281 is not implicitly convertible to expected type uint256.
|
Loading…
Reference in New Issue
Block a user