Browse Source

small fixes per chris's comments

cl-refactor
Lu Guanqun 10 years ago
parent
commit
1372154ff2
  1. 12
      libsolidity/Types.cpp
  2. 2
      test/SolidityEndToEndTest.cpp
  3. 8
      test/SolidityNameAndTypeResolution.cpp

12
libsolidity/Types.cpp

@ -26,6 +26,8 @@
#include <libsolidity/Types.h>
#include <libsolidity/AST.h>
#include <limits>
using namespace std;
namespace dev
@ -322,13 +324,11 @@ TypePointer IntegerConstantType::binaryOperatorResult(Token::Value _operator, Ty
break;
case Token::Exp:
if (other.m_value < 0)
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("exponent can't be negative"));
return TypePointer();
else if (other.m_value > std::numeric_limits<unsigned int>::max())
return TypePointer();
else
{
value = boost::multiprecision::powm(m_value, other.m_value, bigint(2) << 256);
if (value >= (bigint(1) << 256))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("exp result overflowed"));
}
value = boost::multiprecision::pow(m_value, other.m_value.convert_to<unsigned int>());
break;
default:
return TypePointer();

2
test/SolidityEndToEndTest.cpp

@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed)
{
char const* sourceCode = R"(
contract test {
function f() returns(int d) { return -2 ** 3; }
function f() returns(int d) { return (-2) ** 3; }
})";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(-8)));

8
test/SolidityNameAndTypeResolution.cpp

@ -980,16 +980,16 @@ BOOST_AUTO_TEST_CASE(exp_operator_negative_exponent)
contract test {
function f() returns(uint d) { return 2 ** -3; }
})";
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), InternalCompilerError);
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_CASE(exp_operator_const_overflowed)
BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big)
{
char const* sourceCode = R"(
contract test {
function f() returns(uint d) { return 10 ** 256; }
function f() returns(uint d) { return 2 ** 10000000000; }
})";
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), InternalCompilerError);
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save