diff --git a/src-rust/Cargo.lock b/src-rust/Cargo.lock index bcac75a..37fe66d 100644 --- a/src-rust/Cargo.lock +++ b/src-rust/Cargo.lock @@ -992,7 +992,7 @@ checksum = "4bf2521270932c3c7bed1a59151222bd7643c79310f2916f01925e1e16255698" [[package]] name = "reloaded-memory-buffers" -version = "4.0.1" +version = "4.0.2" dependencies = [ "clf", "criterion", diff --git a/src-rust/Cargo.toml b/src-rust/Cargo.toml index 15cbf16..a183392 100644 --- a/src-rust/Cargo.toml +++ b/src-rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reloaded-memory-buffers" -version = "4.0.1" +version = "4.0.2" edition = "2021" authors = [ "sewer56" ] description = "Shared, Concurrent, Permanent Memory Allocator tied to Process Lifetime" diff --git a/src-rust/src/buffers.rs b/src-rust/src/buffers.rs index de3096d..4ec199c 100644 --- a/src-rust/src/buffers.rs +++ b/src-rust/src/buffers.rs @@ -9,6 +9,7 @@ use crate::utilities::disable_write_xor_execute::{ }; use crate::utilities::icache_clear::clear_instruction_cache; use crate::utilities::mathematics::round_up; +use core::cmp::max; use core::ptr::{copy_nonoverlapping, NonNull}; use core::u8; @@ -73,23 +74,15 @@ impl Buffers { ) -> Result { // Add expected size. let mut new_settings = *settings; - new_settings.size += alignment; + new_settings.size += alignment.saturating_sub(1); - let result = Self::get_buffer(&new_settings); - - if result.is_ok() { - // No error. (Hot Path) - return result; - } - - // If we have an error, pass it back. + let result = Self::get_buffer(&new_settings)?; unsafe { - let locator_item_cell = &result.as_ref().unwrap_unchecked().item; - let locator_item = locator_item_cell.get(); + let locator_item = result.item.get(); let base_address = (*locator_item).base_address.value; let aligned_address = round_up(base_address, alignment as usize); (*locator_item).base_address.value = aligned_address; - result + Ok(result) } }