Skip to content

Commit

Permalink
fix: custom page size memory.grow on 32-bit
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Gressmann <[email protected]>
  • Loading branch information
explodingcamera committed Sep 11, 2024
1 parent eb97adc commit 15ab54b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/tinywasm/src/store/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl MemoryInstance {
}

pub(crate) fn max_pages(&self) -> usize {
self.kind.page_count_max() as usize
self.kind.page_count_max().try_into().unwrap_or(usize::MAX)
}

pub(crate) fn load(&self, addr: usize, len: usize) -> Result<&[u8]> {
Expand Down Expand Up @@ -130,6 +130,9 @@ impl MemoryInstance {
debug_assert!(new_pages <= i32::MAX as i64, "page count should never be greater than i32::MAX");

if new_pages < 0 || new_pages as usize > self.max_pages() {
log::debug!("memory.grow failed: new_pages={}, max_pages={}", new_pages, self.max_pages());
log::debug!("{} {}", self.kind.page_count_max(), self.kind.page_size());

return None;
}

Expand Down

0 comments on commit 15ab54b

Please sign in to comment.