diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-18 22:25:32 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-19 14:09:16 +1100 |
| commit | c9b4538babbc85b971b19bbeff16bd12a4f4db54 (patch) | |
| tree | 8efb0c748d1330d1e5bfcb5c9b0c1a14ff92655b /src/libnative | |
| parent | 4f841ee1509fafdf688a3898e01560ae29ee7836 (diff) | |
| download | rust-c9b4538babbc85b971b19bbeff16bd12a4f4db54.tar.gz rust-c9b4538babbc85b971b19bbeff16bd12a4f4db54.zip | |
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.
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/file.rs | 3 |
1 files changed, 2 insertions, 1 deletions
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)); } |
