Skip to content

Commit 7c0f5e3

Browse files
committed
Add debug_assert ensuring popped byte is nul
1 parent 60a70c6 commit 7c0f5e3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/unistd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {
538538
let mut path = try!(template.with_nix_path(|path| {path.to_bytes_with_nul().to_owned()}));
539539
let p = path.as_mut_ptr() as *mut _;
540540
let fd = unsafe { libc::mkstemp(p) };
541-
path.pop(); // drop the trailing nul
541+
let last = path.pop(); // drop the trailing nul
542+
debug_assert!(last == Some(b'\0'));
542543
let pathname = OsString::from_vec(path);
543544
try!(Errno::result(fd));
544545
Ok((fd, PathBuf::from(pathname)))

0 commit comments

Comments
 (0)