mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1307 from ethereum/fixclean
Fix cleanup of higher order bytes prior to store.
This commit is contained in:
commit
1d3460c4e2
@ -4,6 +4,7 @@ Features:
|
|||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* Type checker: forbid signed exponential that led to an incorrect use of EXP opcode.
|
* Type checker: forbid signed exponential that led to an incorrect use of EXP opcode.
|
||||||
|
* Code generator: properly clean higher order bytes before storing in storage.
|
||||||
|
|
||||||
### 0.4.3 (2016-10-25)
|
### 0.4.3 (2016-10-25)
|
||||||
|
|
||||||
|
@ -231,10 +231,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
|
|||||||
m_context
|
m_context
|
||||||
<< (u256(0x1) << (256 - 8 * dynamic_cast<FixedBytesType const&>(*m_dataType).numBytes()))
|
<< (u256(0x1) << (256 - 8 * dynamic_cast<FixedBytesType const&>(*m_dataType).numBytes()))
|
||||||
<< Instruction::SWAP1 << Instruction::DIV;
|
<< Instruction::SWAP1 << Instruction::DIV;
|
||||||
else if (
|
else
|
||||||
m_dataType->category() == Type::Category::Integer &&
|
|
||||||
dynamic_cast<IntegerType const&>(*m_dataType).isSigned()
|
|
||||||
)
|
|
||||||
// remove the higher order bits
|
// remove the higher order bits
|
||||||
m_context
|
m_context
|
||||||
<< (u256(1) << (8 * (32 - m_dataType->storageBytes())))
|
<< (u256(1) << (8 * (32 - m_dataType->storageBytes())))
|
||||||
@ -242,9 +239,6 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
|
|||||||
<< Instruction::DUP2
|
<< Instruction::DUP2
|
||||||
<< Instruction::MUL
|
<< Instruction::MUL
|
||||||
<< Instruction::DIV;
|
<< Instruction::DIV;
|
||||||
else if (m_dataType->category() == Type::Category::FixedPoint)
|
|
||||||
// implementation should be very similar to the integer case.
|
|
||||||
solAssert(false, "Not yet implemented - FixedPointType.");
|
|
||||||
m_context << Instruction::MUL << Instruction::OR;
|
m_context << Instruction::MUL << Instruction::OR;
|
||||||
// stack: value storage_ref updated_value
|
// stack: value storage_ref updated_value
|
||||||
m_context << Instruction::SWAP1 << Instruction::SSTORE;
|
m_context << Instruction::SWAP1 << Instruction::SSTORE;
|
||||||
|
@ -7533,6 +7533,26 @@ BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers)
|
|||||||
BOOST_CHECK(callContractFunction("f()") == encodeArgs(true));
|
BOOST_CHECK(callContractFunction("f()") == encodeArgs(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(packed_storage_overflow)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract C {
|
||||||
|
uint16 x = 0x1234;
|
||||||
|
uint16 a = 0xffff;
|
||||||
|
uint16 b;
|
||||||
|
function f() returns (uint, uint, uint, uint) {
|
||||||
|
a++;
|
||||||
|
uint c = b;
|
||||||
|
delete b;
|
||||||
|
a -= 2;
|
||||||
|
return (x, c, b, a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "C");
|
||||||
|
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0x1234), u256(0), u256(0), u256(0xfffe)));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user