Skip to content

Commit fa0755c

Browse files
committed
Add calloc test
1 parent a59e155 commit fa0755c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/run-pass/calloc.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//ignore-windows: Uses POSIX APIs
2+
3+
#![feature(rustc_private)]
4+
5+
use core::slice;
6+
7+
extern crate libc;
8+
9+
fn main() {
10+
unsafe {
11+
let p1 = libc::calloc(0, 0);
12+
assert!(p1.is_null());
13+
14+
let p2 = libc::calloc(20, 0);
15+
assert!(p2.is_null());
16+
17+
let p3 = libc::calloc(0, 20);
18+
assert!(p3.is_null());
19+
20+
let p4 = libc::calloc(4, 8) as *const u8;
21+
assert!(!p4.is_null());
22+
23+
let slice = slice::from_raw_parts(p4, 4 * 8);
24+
assert_eq!(&slice, &[0_u8; 4 * 8]);
25+
}
26+
}

0 commit comments

Comments
 (0)