Skip to content

Commit

Permalink
Sanity check for the deprecated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Aug 23, 2023
1 parent 6881268 commit 2ba9ed9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions vulkano/src/memory/device_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,18 @@ impl DeviceMemory {

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn map_unchecked(&mut self, map_info: MemoryMapInfo) -> Result<(), VulkanError> {
let device = self.device();

let MemoryMapInfo {
flags,
offset,
size,
_ne: _,
} = map_info;

// Sanity check: this would lead to UB when calculating pointer offsets.
assert!(size <= isize::MAX.try_into().unwrap());

let device = self.device();

let ptr = {
let fns = device.fns();
let mut output = MaybeUninit::uninit();
Expand All @@ -480,9 +483,6 @@ impl DeviceMemory {
output.assume_init()
};

// Sanity check: this would lead to UB when calculating pointer offsets.
assert!(size <= isize::MAX.try_into().unwrap());

let ptr = NonNull::new(ptr).unwrap();
let range = offset..offset + size;
self.mapping_state = Some(MappingState { ptr, range });
Expand Down Expand Up @@ -1794,6 +1794,9 @@ impl MappedDeviceMemory {
memory: DeviceMemory,
range: Range<DeviceSize>,
) -> Result<Self, VulkanError> {
// Sanity check: this would lead to UB when calculating pointer offsets.
assert!(range.end - range.start <= isize::MAX.try_into().unwrap());

let device = memory.device();

let pointer = unsafe {
Expand Down

0 comments on commit 2ba9ed9

Please sign in to comment.