]> git.lizzy.rs Git - rust.git/commitdiff
Fix calloc test
authorTim Diekmann <tim.diekmann@3dvision.de>
Sun, 7 Apr 2019 23:26:52 +0000 (01:26 +0200)
committerTim Diekmann <tim.diekmann@3dvision.de>
Sun, 7 Apr 2019 23:26:52 +0000 (01:26 +0200)
Forgot to free the memory. Miri found the bug :)

tests/run-pass/calloc.rs

index 8e8e2e5f10f4f9fb8b20cb38a76b1873af4808e5..4c520da85e876d190c7324902921d3898f09d3a3 100644 (file)
@@ -17,10 +17,10 @@ fn main() {
         let p3 = libc::calloc(0, 20);
         assert!(p3.is_null());
 
-        let p4 = libc::calloc(4, 8) as *const u8;
+        let p4 = libc::calloc(4, 8);
         assert!(!p4.is_null());
-
-        let slice = slice::from_raw_parts(p4, 4 * 8);
+        let slice = slice::from_raw_parts(p4 as *const u8, 4 * 8);
         assert_eq!(&slice, &[0_u8; 4 * 8]);
+        libc::free(p4);
     }
 }