Skip to content

Commit 08c531d

Browse files
committed
Fix incorrect score being returned for unrecognized byte pairs
1 parent a7f96d9 commit 08c531d

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/Scanner.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ namespace hat::detail {
1515
#ifdef LIBHAT_HINT_X86_64
1616
const bool x86_64 = static_cast<bool>(this->hints & scan_hint::x86_64);
1717
if (x86_64 && !pair0 && scanner.vectorSize) {
18-
static constexpr auto getScore = [](const std::byte a, const std::byte b) {
18+
static constexpr auto getScore = [](const std::byte a, const std::byte b) -> uint16_t {
1919
constexpr auto& pairs = hat::detail::x86_64::pairs_x1;
20+
constexpr auto& scores = hat::detail::x86_64::scores_x1;
21+
static_assert(pairs.size() == scores.size());
22+
23+
constexpr auto max = static_cast<uint16_t>(scores.size());
24+
2025
const std::pair pair{a, b};
2126
const auto it = std::ranges::lower_bound(pairs, pair);
2227
const auto index = static_cast<uint16_t>(it - pairs.begin());
23-
if (it != pairs.end() && *it == pair) {
24-
return hat::detail::x86_64::scores_x1[index];
25-
}
26-
return index;
28+
return it != pairs.end() && *it == pair ? scores[index] : max;
2729
};
2830

2931
std::optional<std::pair<size_t, uint16_t>> bestPair{};

0 commit comments

Comments
 (0)