Skip to content

Commit

Permalink
Don't require sequential missing section error numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed May 4, 2023
1 parent b42e168 commit d019f28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 14 additions & 4 deletions lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "baseline_instruction_table.hpp"
#include "instructions_traits.hpp"

#include <intx/intx.hpp>
#include <algorithm>
#include <array>
#include <cassert>
Expand Down Expand Up @@ -48,8 +49,19 @@ size_t eof_header_size(const EOFSectionHeaders& headers) noexcept

EOFValidationError get_section_missing_error(uint8_t section_id) noexcept
{
return static_cast<EOFValidationError>(
static_cast<uint8_t>(EOFValidationError::header_terminator_missing) + section_id);
switch (section_id)
{
case TERMINATOR:
return EOFValidationError::header_terminator_missing;
case TYPE_SECTION:
return EOFValidationError::type_section_missing;
case CODE_SECTION:
return EOFValidationError::code_section_missing;
case DATA_SECTION:
return EOFValidationError::data_section_missing;
default:
intx::unreachable();
}
}

std::variant<EOFSectionHeaders, EOFValidationError> validate_eof_headers(bytes_view container)
Expand Down Expand Up @@ -565,8 +577,6 @@ std::string_view get_error_message(EOFValidationError err) noexcept
return "type_section_missing";
case EOFValidationError::code_section_missing:
return "code_section_missing";
case EOFValidationError::unknown_section_id:
return "unknown_section_id";
case EOFValidationError::data_section_missing:
return "data_section_missing";
case EOFValidationError::zero_section_size:
Expand Down
1 change: 0 additions & 1 deletion lib/evmone/eof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ enum class EOFValidationError
header_terminator_missing,
type_section_missing,
code_section_missing,
unknown_section_id,
data_section_missing,
zero_section_size,
section_headers_not_terminated,
Expand Down

0 comments on commit d019f28

Please sign in to comment.