about summary refs log tree commit diff
path: root/src/libstd/os.rs
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-02-17 09:57:56 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2014-02-18 00:00:38 +1100
commit4f841ee1509fafdf688a3898e01560ae29ee7836 (patch)
tree109fd76eab98758829ab5ebde99d8a8477b1853e /src/libstd/os.rs
parent35b1b62ddfc31c2e52b65c2f908c0fcbc6465de5 (diff)
downloadrust-4f841ee1509fafdf688a3898e01560ae29ee7836.tar.gz
rust-4f841ee1509fafdf688a3898e01560ae29ee7836.zip
std: make str::from_utf16 return an Option.
The rest of the codebase is moving toward avoiding `fail!` so we do it
here too!
Diffstat (limited to 'src/libstd/os.rs')
-rw-r--r--src/libstd/os.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 719ed62d03d..31e88905b30 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -88,7 +88,7 @@ pub fn getcwd() -> Path {
             fail!();
         }
     }
-    Path::new(str::from_utf16(buf))
+    Path::new(str::from_utf16(buf).expect("GetCurrentDirectoryW returned invalid UTF-16"))
 }
 
 #[cfg(windows)]
@@ -124,7 +124,12 @@ pub mod win32 {
                 }
                 if k != 0 && done {
                     let sub = buf.slice(0, k as uint);
-                    res = option::Some(str::from_utf16(sub));
+                    // We want to explicitly catch the case when the
+                    // closure returned invalid UTF-16, rather than
+                    // set `res` to None and continue.
+                    let s = str::from_utf16(sub)
+                        .expect("fill_utf16_buf_and_decode: closure created invalid UTF-16");
+                    res = option::Some(s)
                 }
             }
             return res;
@@ -739,7 +744,7 @@ pub fn last_os_error() -> ~str {
                 fail!("[{}] FormatMessage failure", errno());
             }
 
-            str::from_utf16(buf)
+            str::from_utf16(buf).expect("FormatMessageW returned invalid UTF-16")
         }
     }
 
@@ -828,8 +833,8 @@ fn real_args() -> ~[~str] {
             while *ptr.offset(len as int) != 0 { len += 1; }
 
             // Push it onto the list.
-            args.push(vec::raw::buf_as_slice(ptr, len,
-                                             str::from_utf16));
+            let opt_s = vec::raw::buf_as_slice(ptr, len, str::from_utf16);
+            args.push(opt_s.expect("CommandLineToArgvW returned invalid UTF-16"));
         }
     }