Fix panic in fwrite

This commit is contained in:
lmiskiew
2018-12-17 02:01:36 +01:00
parent f04ac7343a
commit 5b6b11cb65
8 changed files with 33 additions and 4 deletions
+5 -2
View File
@@ -562,11 +562,14 @@ pub unsafe extern "C" fn funlockfile(file: *mut FILE) {
pub unsafe extern "C" fn fwrite(
ptr: *const c_void,
size: size_t,
count: size_t,
nitems: size_t,
stream: *mut FILE,
) -> size_t {
if size == 0 || nitems == 0 {
return 0
}
let mut stream = (*stream).lock();
let buf = slice::from_raw_parts_mut(ptr as *mut u8, size as usize * count as usize);
let buf = slice::from_raw_parts_mut(ptr as *mut u8, size as usize * nitems as usize);
let mut written = 0;
while written < buf.len() {
match stream.write(&mut buf[written..]) {