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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user