mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Pad code to multiple of 32 bytes.
This commit is contained in:
parent
d6b8521ed5
commit
35483422f3
@ -1,6 +1,7 @@
|
||||
### 0.5.4 (unreleased)
|
||||
|
||||
Bugfixes:
|
||||
* Code generator: Defensively pad allocation of creationCode and runtimeCode to multiples of 32 bytes.
|
||||
* Parser: Disallow empty import statements.
|
||||
* Type system: Properly report packed encoded size for arrays and structs (mostly unused until now).
|
||||
|
||||
|
@ -1348,7 +1348,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
m_context.appendInlineAssembly(
|
||||
Whiskers(R"({
|
||||
mstore(start, sub(end, add(start, 0x20)))
|
||||
mstore(<free>, end)
|
||||
mstore(<free>, and(add(end, 31), not(31)))
|
||||
})")("free", to_string(CompilerUtils::freeMemoryPointer)).render(),
|
||||
{"start", "end"}
|
||||
);
|
||||
|
@ -14275,6 +14275,25 @@ BOOST_AUTO_TEST_CASE(code_access)
|
||||
ABI_CHECK(codeRuntime1, codeRuntime2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(code_access_padding)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function diff() public pure returns (uint remainder) {
|
||||
bytes memory a = type(D).creationCode;
|
||||
bytes memory b = type(D).runtimeCode;
|
||||
assembly { remainder := mod(sub(b, a), 0x20) }
|
||||
}
|
||||
}
|
||||
contract D {
|
||||
function f() public pure returns (uint) { return 7; }
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
// This checks that the allocation function pads to multiples of 32 bytes
|
||||
ABI_CHECK(callContractFunction("diff()"), encodeArgs(0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(code_access_create)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user