Skip to content

Commit

Permalink
std: Fix over-aligned allocations on wasm32-wasi
Browse files Browse the repository at this point in the history
The wasm32-wasi target delegates its malloc implementation to the
functions in wasi-libc, but the invocation of `aligned_alloc` was
incorrect by passing the number of bytes requested first rather than the
alignment. This commit swaps the order of these two arguments to ensure
that we allocate over-aligned memory correctly.
  • Loading branch information
alexcrichton committed Mar 30, 2020
1 parent 9a12971 commit ab2998b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/sys/wasi/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unsafe impl GlobalAlloc for System {
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
libc::malloc(layout.size()) as *mut u8
} else {
libc::aligned_alloc(layout.size(), layout.align()) as *mut u8
libc::aligned_alloc(layout.align(), layout.size()) as *mut u8
}
}

Expand Down

0 comments on commit ab2998b

Please sign in to comment.