2022-07-17 20:54:10 -05:00
|
|
|
//@ignore-target-windows: No libc on Windows
|
2019-04-07 18:12:50 -05:00
|
|
|
|
2020-11-10 09:51:07 -06:00
|
|
|
use core::slice;
|
|
|
|
|
2019-04-07 18:12:50 -05:00
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let p1 = libc::calloc(0, 0);
|
|
|
|
assert!(p1.is_null());
|
|
|
|
|
|
|
|
let p2 = libc::calloc(20, 0);
|
|
|
|
assert!(p2.is_null());
|
|
|
|
|
|
|
|
let p3 = libc::calloc(0, 20);
|
|
|
|
assert!(p3.is_null());
|
|
|
|
|
2019-04-07 18:26:52 -05:00
|
|
|
let p4 = libc::calloc(4, 8);
|
2019-04-07 18:12:50 -05:00
|
|
|
assert!(!p4.is_null());
|
2019-04-07 18:26:52 -05:00
|
|
|
let slice = slice::from_raw_parts(p4 as *const u8, 4 * 8);
|
2019-04-07 18:12:50 -05:00
|
|
|
assert_eq!(&slice, &[0_u8; 4 * 8]);
|
2019-04-07 18:26:52 -05:00
|
|
|
libc::free(p4);
|
2019-04-07 18:12:50 -05:00
|
|
|
}
|
|
|
|
}
|