From c9b4538babbc85b971b19bbeff16bd12a4f4db54 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 18 Feb 2014 22:25:32 +1100 Subject: str: add a function for truncating a vector of u16 at NUL. Many of the functions interacting with Windows APIs allocate a vector of 0's and do not retrieve a length directly from the API call, and so need to be sure to remove the unmodified junk at the end of the vector. --- src/libnative/io/file.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libnative') diff --git a/src/libnative/io/file.rs b/src/libnative/io/file.rs index 80f5f74c53a..6d3a156a2b0 100644 --- a/src/libnative/io/file.rs +++ b/src/libnative/io/file.rs @@ -571,7 +571,8 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { else { let fp_vec = vec::from_buf( fp_buf, wcslen(fp_buf) as uint); - let fp_str = str::from_utf16(fp_vec) + let fp_trimmed = str::truncate_utf16_at_nul(fp_vec); + let fp_str = str::from_utf16(fp_trimmed) .expect("rust_list_dir_wfd_fp_buf returned invalid UTF-16"); paths.push(Path::new(fp_str)); } -- cgit 1.4.1-3-g733a5