From cbbf09a69d76a46bb685a85169f0076e884c90cb Mon Sep 17 00:00:00 2001 From: fmiguelgarcia Date: Fri, 12 Jul 2024 11:43:20 +0200 Subject: [PATCH 1/2] Enforce `max_rows` & `max_cols` as power of 2 --- kate/src/com.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kate/src/com.rs b/kate/src/com.rs index df88738..d9eb36a 100644 --- a/kate/src/com.rs +++ b/kate/src/com.rs @@ -94,6 +94,8 @@ pub enum Error { ExtendedGridDomainSizeInvalid(usize), IndexOutOfRange, ConversionFailed, + InvalidMaxRows, + InvalidMaxCols, } impl From for Error { @@ -227,6 +229,12 @@ pub fn get_block_dimensions( let () = USizeSafeCastToU32::::OK; let chunk_size_u32 = unsafe { NonZeroU32::new_unchecked(CHUNK_SIZE as u32) }; + // SAFETY: `max_rows` and `max_cols` must be a power of 2. + // Otherwise block dimensions will be one row short, as the + // row count equals `total_cells / max_cols1`. + ensure!(max_rows.0.is_power_of_two(), Error::InvalidMaxRows); + ensure!(max_cols.0.is_power_of_two(), Error::InvalidMaxCols); + let max_block_dimensions = BlockDimensions::new(max_rows, max_cols, chunk_size_u32).ok_or(Error::BlockTooBig)?; let max_block_dimensions_size = max_block_dimensions.size(); From 49711045f11d8621a58b3031c6282ccd679df3a0 Mon Sep 17 00:00:00 2001 From: fmiguelgarcia Date: Fri, 12 Jul 2024 11:44:52 +0200 Subject: [PATCH 2/2] bump crate version --- kate/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kate/Cargo.toml b/kate/Cargo.toml index 487731f..513bc88 100644 --- a/kate/Cargo.toml +++ b/kate/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kate" -version = "0.9.1" +version = "0.9.2" authors = ["Denis Ermolin "] edition = "2021" license = "Apache-2.0"