Skip to content

Commit

Permalink
also add imported memory debug assert
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jun 28, 2023
1 parent 9d7adb0 commit 88ab394
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ impl Instance {
/// Return the indexed `VMMemoryImport`.
fn imported_memory(&self, index: MemoryIndex) -> &VMMemoryImport {
let index = usize::try_from(index.as_u32()).unwrap();
unsafe { &*self.imported_memories_ptr().add(index) }
let addr = unsafe { self.imported_memories_ptr().add(index) };
let align = std::mem::align_of::<VMMemoryImport>();
debug_assert!(
addr as usize % align == 0,
"VMMemoryImport addr is not aligned to {}: {:p}",
align,
addr
);
unsafe { &*addr }
}

/// Return a pointer to the `VMMemoryImport`s.
Expand Down

0 comments on commit 88ab394

Please sign in to comment.