Skip to content

Commit 5339a58

Browse files
authored
fix: Buffer slice end does not need to be aligned (#5734)
Only start positions need to match the alignment. --------- Signed-off-by: Alexander Droste <[email protected]>
1 parent 0562416 commit 5339a58

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

vortex-buffer/src/buffer.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,6 @@ impl<T> Buffer<T> {
321321
if !begin_byte.is_multiple_of(*alignment) {
322322
vortex_panic!("range start must be aligned to {alignment:?}");
323323
}
324-
if !end_byte.is_multiple_of(*alignment) {
325-
vortex_panic!("range end must be aligned to {alignment:?}");
326-
}
327324
if !alignment.is_aligned_to(Alignment::of::<T>()) {
328325
vortex_panic!("Slice alignment must at least align to type T")
329326
}
@@ -744,4 +741,16 @@ mod test {
744741
assert!(buff.is_aligned(Alignment::of::<i32>()));
745742
assert_eq!(vec, buff);
746743
}
744+
745+
#[test]
746+
fn test_slice_unaligned_end_pos() {
747+
let data = vec![0u8; 2];
748+
// Overalign the u8 vector.
749+
let aligned_buffer = Buffer::copy_from_aligned(&data, Alignment::new(8));
750+
// Previously, `Buffer::slice` incorrectly asserted that the end position
751+
// must be aligned. That assertion has been removed such that the end
752+
// position can be arbitrary and only the beginning of the slice needs
753+
// to be aligned.
754+
aligned_buffer.slice(0..1);
755+
}
747756
}

0 commit comments

Comments
 (0)