Borrow value instead of moving in FsPath::from()

When accepting a value of AsRef<Utf8CStr> in FsPath::from(), the
existing code will move a value of Utf8CStrBufArr, creating a reference
that lives longer than the borrowing value, causing undefined behavior.

The issue is only visible on release builds, as more advanced
optimizations will be more aggressive re-using the stack of variables
that no longer lives.

Fix #7408
This commit is contained in:
topjohnwu
2023-10-11 23:48:54 -07:00
parent 587b6cfd41
commit eda8c70a80
2 changed files with 4 additions and 4 deletions

View File

@@ -229,13 +229,13 @@ impl DirEntry<'_> {
pub fn get_attr(&self) -> io::Result<FileAttr> {
let mut path = Utf8CStrBufArr::default();
self.path(&mut path)?;
FsPath::from(path).get_attr()
FsPath::from(&path).get_attr()
}
pub fn set_attr(&self, attr: &FileAttr) -> io::Result<()> {
let mut path = Utf8CStrBufArr::default();
self.path(&mut path)?;
FsPath::from(path).set_attr(attr)
FsPath::from(&path).set_attr(attr)
}
}