allocarray

Function allocarray 

Source
pub fn allocarray<'a>(count: size_t, size: size_t) -> &'a mut [u8] 
Expand description

The allocarray() function returns a mutable byte array.

It provides the same guarantees as malloc() but also protects against arithmetic overflows when count * size exceeds SIZE_MAX.

allocarray() safely wraps sodium_allocarray().

§Examples

use sodium_sys::crypto::utils::init::init;
use sodium_sys::crypto::utils::secmem::{allocarray,free};

let _ = init();
let mut v = allocarray(2, 16);
v[0] = 1;
assert!(v.len() == 32);
assert!(v[0] == 1);
free(v);