Skip to content

Commit

Permalink
baseline: Refactor code padding (#517)
Browse files Browse the repository at this point in the history
Use std::make_unique_for_overwrite to create padded code.
  • Loading branch information
chfast authored Mar 26, 2024
1 parent 2205fb3 commit 8358ba0
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ std::unique_ptr<uint8_t[]> pad_code(bytes_view code)
// instruction at the code end.
constexpr auto padding = 32 + 1;

// Using "raw" new operator instead of std::make_unique() to get uninitialized array.
std::unique_ptr<uint8_t[]> padded_code{new uint8_t[code.size() + padding]};
auto padded_code = std::make_unique_for_overwrite<uint8_t[]>(code.size() + padding);
std::copy(std::begin(code), std::end(code), padded_code.get());
std::fill_n(&padded_code[code.size()], padding, uint8_t{OP_STOP});
return padded_code;
Expand Down

0 comments on commit 8358ba0

Please sign in to comment.