From a7f80094de9d0eb7a5c72b4dc483746bc46aecdc Mon Sep 17 00:00:00 2001 From: safe4u Date: Tue, 9 Jul 2024 10:52:05 +0800 Subject: [PATCH 1/2] Fix the unsond problem in Rows --- src/compute/sort/row/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compute/sort/row/mod.rs b/src/compute/sort/row/mod.rs index 2388a6c8680..75855d5521f 100644 --- a/src/compute/sort/row/mod.rs +++ b/src/compute/sort/row/mod.rs @@ -260,6 +260,10 @@ pub struct Rows { impl Rows { /// Get a reference to a certain row. + /// + /// # Panics + /// + /// Panics if `row` is out of bounds pub fn row(&self, row: usize) -> Row<'_> { let end = self.offsets[row + 1]; let start = self.offsets[row]; @@ -269,7 +273,12 @@ impl Rows { } /// Get a reference to a certain row but not check the bounds. - pub fn row_unchecked(&self, row: usize) -> Row<'_> { + /// + /// # Safety + /// + /// The caller must ensure that `row` is within bounds + pub unsafe fn row_unchecked(&self, row: usize) -> Row<'_> { + debug_assert!(row < self.len(), "out-of-bounds access"); let data = unsafe { let end = *self.offsets.get_unchecked(row + 1); let start = *self.offsets.get_unchecked(row); From b569f831663949ee1f8494ffed462ac5e3047cbb Mon Sep 17 00:00:00 2001 From: safe4u Date: Tue, 9 Jul 2024 10:52:05 +0800 Subject: [PATCH 2/2] Update affected use of row_unchecked --- src/compute/sort/row/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compute/sort/row/mod.rs b/src/compute/sort/row/mod.rs index 75855d5521f..7d27e5a1f58 100644 --- a/src/compute/sort/row/mod.rs +++ b/src/compute/sort/row/mod.rs @@ -260,9 +260,9 @@ pub struct Rows { impl Rows { /// Get a reference to a certain row. - /// + /// /// # Panics - /// + /// /// Panics if `row` is out of bounds pub fn row(&self, row: usize) -> Row<'_> { let end = self.offsets[row + 1]; @@ -273,9 +273,9 @@ impl Rows { } /// Get a reference to a certain row but not check the bounds. - /// + /// /// # Safety - /// + /// /// The caller must ensure that `row` is within bounds pub unsafe fn row_unchecked(&self, row: usize) -> Row<'_> { debug_assert!(row < self.len(), "out-of-bounds access"); @@ -328,7 +328,7 @@ impl<'a> Iterator for RowsIter<'a> { #[inline] fn next(&mut self) -> Option { if self.start < self.end { - let row = self.rows.row_unchecked(self.start); + let row = unsafe { self.rows.row_unchecked(self.start) }; self.start += 1; Some(row) } else {