Skip to content

Commit 5404648

Browse files
committed
Merge #370: fix: prevent silent overflow in calloc
11153bb fix: prevent silent overflow in calloc (stringhandler) Pull request description: Minor overflow prevention. Overflow can silently occur in release builds. Low priority but simple enough fix. ACKs for top commit: delta1: ACK 11153bb; tested locally apoelstra: ACK 11153bb; successfully ran local tests Tree-SHA512: 907ff678cace034cd36f2cc0dfef1bf07c0cca673d1e2f33ac8bbf2d2bc1c4c9c86b6d5c7a9137cd587105b9e53bbcd21cef6dca8fdfd20faec79294920e61f1
2 parents 160d782 + 11153bb commit 5404648

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)