Fix sign-extension in FNV-1/FNV-1a byte processing; add std::byte support - #4
Merged
Conversation
Co-authored-by: rwindegger <12802869+rwindegger@users.noreply.github.com> Agent-Logs-Url: https://github.com/rwindegger/hash23/sessions/d5360797-5255-4a5c-894c-557dbe66639c
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on FNV-1 and FNV-1a hash implementations and tests
Fix sign-extension in FNV-1/FNV-1a byte processing; add std::byte support
Mar 22, 2026
rwindegger
reviewed
Mar 22, 2026
…tension fix Co-authored-by: rwindegger <12802869+rwindegger@users.noreply.github.com> Agent-Logs-Url: https://github.com/rwindegger/hash23/sessions/6053785c-94b8-4fc9-bf5c-d1cce881240e
rwindegger
approved these changes
Mar 22, 2026
Owner
|
@copilot is this pr ready? |
Contributor
Author
Yes — all review threads are resolved and all CI checks on this branch are green. The PR is ready to merge. |
rwindegger
marked this pull request as ready for review
March 22, 2026 12:11
rwindegger
added a commit
that referenced
this pull request
Mar 22, 2026
* Add FNV-1 and FNV-1a hash implementations with corresponding tests * Refactor FNV-1 and FNV-1a hash implementations to remove buffer usage and improve hash calculation efficiency * Add string and empty input tests for FNV-1 and FNV-1a hash implementations * Fix type casting in FNV-1 and FNV-1a hash update methods for byte processing * Add missing includes for cstddef and string in FNV-1 and FNV-1a headers and tests * Fix type casting in FNV-1 and FNV-1a hash update methods to use uint8_t * Fix sign-extension in FNV-1/FNV-1a byte processing; add std::byte support (#4) * Initial plan * Handle std::byte via std::to_integer and add high-byte value tests Co-authored-by: rwindegger <12802869+rwindegger@users.noreply.github.com> Agent-Logs-Url: https://github.com/rwindegger/hash23/sessions/d5360797-5255-4a5c-894c-557dbe66639c * Use signed char in high_byte_values_test to directly exercise sign-extension fix Co-authored-by: rwindegger <12802869+rwindegger@users.noreply.github.com> Agent-Logs-Url: https://github.com/rwindegger/hash23/sessions/6053785c-94b8-4fc9-bf5c-d1cce881240e --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rwindegger <12802869+rwindegger@users.noreply.github.com> * Reorder includes and update high byte values in FNV-1 and FNV-1a tests * Restrict FNV-1 and FNV-1a update method to contiguous ranges of byte-sized types * Restrict FNV-1 and FNV-1a methods to contiguous ranges of byte-sized types * Update FNV-1 and FNV-1a methods to use std::ranges::range_value_t for type checks --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: rwindegger <12802869+rwindegger@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
update()was casting range elements directly tostd::size_t, causing sign-extension on platforms wherecharis signed (bytes ≥ 0x80 would expand to e.g.0xFFFFFFFFFFFFFF80), producing incorrect and platform-dependent hashes.Changes
fnv_1.h/fnv_1a.h:update()now usesif constexprto dispatch byte normalization:std::byte→std::to_integer<std::uint8_t>()(idiomatic)static_cast<std::uint8_t>()(strips sign-extension)<cstdint>and<type_traits>includesfnv_1_tests.cpp/fnv_1a_tests.cpp: Addedhigh_byte_values_test(std::vector<signed char>with values ≥ 0x80, e.g.static_cast<signed char>(0x80)= -128) andstd_byte_test(std::vector<std::byte>) — both asserting identical results against known-correct 32-bit and 64-bit reference values. Usingsigned chardirectly exercises the sign-extension path the fix guards against.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.