From 88ab394b94c889a2e25014563b5a334cbf458780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 28 Jun 2023 15:50:43 +0100 Subject: [PATCH] also add imported memory debug assert --- lib/vm/src/instance/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vm/src/instance/mod.rs b/lib/vm/src/instance/mod.rs index bed09bbbfc6..d25810abf77 100644 --- a/lib/vm/src/instance/mod.rs +++ b/lib/vm/src/instance/mod.rs @@ -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::(); + 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.