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" 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();