Skip to content

Commit 11153bb

Browse files
committed
fix: prevent silent overflow in calloc
1 parent a8896cf commit 11153bb

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

simplicity-sys/src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub unsafe extern "C" fn rust_0_7_malloc(size_bytes: usize) -> *mut u8 {
8787
/// Allocated bytes must be freed using [`rust_0_7_free`].
8888
#[no_mangle]
8989
pub unsafe extern "C" fn rust_0_7_calloc(num: usize, size: usize) -> *mut u8 {
90-
let size_bytes = num * size;
90+
let size_bytes = num.saturating_mul(size);
9191
// SAFETY: Allocator is `alloc_alloc_zeroed`.
9292
allocate(size_bytes, alloc::alloc_zeroed)
9393
}

0 commit comments

Comments
 (0)