Skip to content

Commit

Permalink
Fix zero-sized entry issue by including end when sorting entries
Browse files Browse the repository at this point in the history
  • Loading branch information
milasudril committed Jul 5, 2023
1 parent 0856294 commit 529c09d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ std::vector<Wad64::DirEntry> Wad64::fileOffsets(Wad64::Directory const& dir)
file_offsets.reserve(std::size(entries));
std::ranges::transform(
entries, std::back_inserter(file_offsets), [](auto const& item) { return item.second; });
std::ranges::sort(file_offsets, [](auto a, auto b) { return a.begin < b.begin; });
std::ranges::sort(file_offsets);

return file_offsets;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/directory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Wad64
int64_t begin;
int64_t end;

auto operator<=>(DirEntry const& a) const = default;
constexpr auto operator<=>(DirEntry const& a) const = default;
};

struct Gap
Expand Down
4 changes: 2 additions & 2 deletions lib/directory.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ namespace Testcases
Wad64::FileLump{0xde, 0x0, {'A'}},
Wad64::FileLump{0xde, 0x0, {'B'}},
Wad64::FileLump{0x18, 0xc6, {'C'}},
Wad64::FileLump{0x18 + 0xc6, 0x0, {'D'}},
Wad64::FileLump{0x18 + 0xc6, 0x0, {'E'}},
Wad64::FileLump{0x18, 0x0, {'D'}},
Wad64::FileLump{0x18, 0x0, {'E'}},
Wad64::FileLump{0xed, 0xd4, {'F'}}
};

Expand Down

0 comments on commit 529c09d

Please sign in to comment.