You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two real bugs flagged by CodeRabbit's outside-diff review on b44fe59.
P1 — `pack_leaf` was non-bijective via unwrap_or fallbacks (mode.rs:194):
Hand-constructing a `LeafCu { mode: Merge, merge_dir: None, .. }`
serialized as `LeafCu::merge(.., MergeDir::North)` — silently rewriting
malformed input into a different valid leaf and hiding upstream invariant
breaks. Now uses `?` to short-circuit with None when required fields are
missing for the mode (Merge needs merge_dir; Delta needs delta; Escape
needs escape_idx). The `LeafCu::merge/delta/escape` constructors still
enforce the invariants — only struct-literal bypass callers can hit the
rejection.
+ 3 regression tests: leaf_pack_rejects_malformed_merge_without_dir,
leaf_pack_rejects_malformed_delta_without_value,
leaf_pack_rejects_malformed_escape_without_idx
+ pack_leaf docstring documents the bijective contract.
P1 — `BASIN_NONE` collided with `MAX_BASIN_IDX` at 4095 (mode.rs:69):
Both equaled `(1 << 12) - 1`, so basin 4095 was ambiguous — a real
basin and the "no basin" sentinel had the same encoded value.
Now: MAX_BASIN_IDX = 4094 (highest real basin), BASIN_NONE = 4095
(sentinel one slot above). Introduced private BASIN_FIELD_MASK = 0x0FFF
for header packing/unpacking — independent of MAX_BASIN_IDX so BASIN_NONE
still round-trips through the 12-bit field as a sentinel marker.
pack_header/unpack_header switched from `& MAX_BASIN_IDX` (would wrongly
clear bit 0 with 0xFFE) to `& BASIN_FIELD_MASK`.
+ 2 regression tests: basin_none_distinct_from_max_basin_idx,
header_round_trips_max_basin_idx_and_basin_none_distinctly
+ MAX_BASIN_IDX + BASIN_NONE doctests updated to assert the new
relationship.
Gates:
cargo test --features codec --lib hpc::codec → 55 passed (+5)
cargo test --features codec --doc hpc::codec → 15 passed
cargo fmt --all -- --check → clean
cargo clippy --features codec --lib -- -D warnings → clean
0 commit comments