From ae2a5ecbf600495a80ae4d99853a2ed2c8f6b5e9 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 17 Jan 2014 20:45:48 -0500 Subject: handle zero-size allocations correctly The `malloc` family of functions may return a null pointer for a zero-size allocation, which should not be interpreted as an out-of-memory error. If the implementation does not return a null pointer, then handling this will result in memory savings for zero-size types. This also switches some code to `malloc_raw` in order to maintain a centralized point for handling out-of-memory in `rt::global_heap`. Closes #11634 --- src/libnative/io/file.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libnative') diff --git a/src/libnative/io/file.rs b/src/libnative/io/file.rs index 49290434785..9e1bc977082 100644 --- a/src/libnative/io/file.rs +++ b/src/libnative/io/file.rs @@ -13,7 +13,7 @@ use std::c_str::CString; use std::io::IoError; use std::io; -use std::libc::c_int; +use std::libc::{c_int, c_void}; use std::libc; use std::os; use std::rt::rtio; @@ -548,7 +548,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { let p = Path::new(p); let star = p.join("*"); as_utf16_p(star.as_str().unwrap(), |path_ptr| { - let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint); + let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint) as *c_void; let find_handle = FindFirstFileW(path_ptr, wfd_ptr as HANDLE); if find_handle as libc::c_int != INVALID_HANDLE_VALUE { let mut paths = ~[]; -- cgit 1.4.1-3-g733a5