about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-18 19:26:50 -0800
committerbors <bors@rust-lang.org>2014-02-18 19:26:50 -0800
commitcae5999a542fc391e9764ca181f6ac39beec06cb (patch)
tree7967b6c7873af7e70c4ed781db376fddca9e6aa0 /src/libnative
parenta25f44783546333e90b88f5af798fda692de7324 (diff)
parentc9b4538babbc85b971b19bbeff16bd12a4f4db54 (diff)
downloadrust-cae5999a542fc391e9764ca181f6ac39beec06cb.tar.gz
rust-cae5999a542fc391e9764ca181f6ac39beec06cb.zip
auto merge of #12317 : huonw/rust/utf16, r=alexcrichton
Iterators! Use them (in `is_utf16`), create them (in `utf16_items`).

Handle errors gracefully (`from_utf16_lossy`) and `from_utf16` returning `Option<~str>` instead of failing.

Add a pile of tests.
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/io/file.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libnative/io/file.rs b/src/libnative/io/file.rs
index e9c9f51966c..6d3a156a2b0 100644
--- a/src/libnative/io/file.rs
+++ b/src/libnative/io/file.rs
@@ -571,7 +571,9 @@ 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));
                         }
                         more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);