summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2013-08-14 19:19:29 -0700
committerKevin Ballard <kevin@sb.org>2013-08-15 01:32:10 -0700
commit48265b779fabf865a4b05f000ea1575c90e3cd73 (patch)
tree70e4fc83ed145142c5f7b53440e2ff7f9181ad29 /src/libstd/path.rs
parent1e4f13f95fc629bcee2ad9a766d9af7c7b2e18f7 (diff)
downloadrust-48265b779fabf865a4b05f000ea1575c90e3cd73.tar.gz
rust-48265b779fabf865a4b05f000ea1575c90e3cd73.zip
Check for interior nulls in .to_c_str()
Previous dicussions about CString suggested that interior nulls should
throw an error. This was never implemented. Add this now, using a
condition (named null_byte) to allow for recovery.

Add method .to_c_str_unchecked() that skips this check.
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 177f0efb6da..7f53ddf6e79 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -569,6 +569,10 @@ impl ToCStr for PosixPath {
     fn to_c_str(&self) -> c_str::CString {
         self.to_str().to_c_str()
     }
+
+    unsafe fn to_c_str_unchecked(&self) -> c_str::CString {
+        self.to_str().to_c_str_unchecked()
+    }
 }
 
 // FIXME (#3227): when default methods in traits are working, de-duplicate
@@ -781,6 +785,10 @@ impl c_str::ToCStr for WindowsPath {
     fn to_c_str(&self) -> c_str::CString {
         self.to_str().to_c_str()
     }
+
+    unsafe fn to_c_str_unchecked(&self) -> c_str::CString {
+        self.to_str().to_c_str_unchecked()
+    }
 }
 
 impl GenericPath for WindowsPath {