1
Fork 0

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.
This commit is contained in:
Kevin Ballard 2013-08-14 19:19:29 -07:00
parent 1e4f13f95f
commit 48265b779f
2 changed files with 108 additions and 13 deletions

View file

@ -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 {