Browse Source

fixed assigning negative number to unsigned

cl-refactor
Liana Husikyan 10 years ago
parent
commit
ee2b5e7cb4
  1. 2
      libsolidity/Types.cpp
  2. 10
      test/libsolidity/SolidityNameAndTypeResolution.cpp

2
libsolidity/Types.cpp

@ -371,7 +371,7 @@ bool IntegerConstantType::isImplicitlyConvertibleTo(Type const& _convertTo) cons
if (m_value <= (u256(-1) >> (256 - targetType->getNumBits() + forSignBit)))
return true;
}
else if (-m_value <= (u256(1) << (targetType->getNumBits() - forSignBit)))
else if (targetType->isSigned() && -m_value <= (u256(1) << (targetType->getNumBits() - forSignBit)))
return true;
return false;
}

10
test/libsolidity/SolidityNameAndTypeResolution.cpp

@ -1866,6 +1866,16 @@ BOOST_AUTO_TEST_CASE(negative_integers_to_unsigned)
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_CASE(positive_integers_to_unsigned_out_of_bound)
{
char const* sourceCode = R"(
contract test {
uint8 public x = 700;
}
)";
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_SUITE_END()
}

Loading…
Cancel
Save