more precise RawDirEntry lifetime#1552
Conversation
|
Thanks! |
|
No, this is UB. Please revert. Here is a test that should be added to a fn main() {
let mut buf = [MaybeUninit::uninit(); 47];
let fd = openat(CWD, c".", OFlags::DIRECTORY, Mode::empty()).unwrap();
let mut iter = RawDir::new(fd, &mut buf);
let item1 = iter.next().unwrap();
let item2 = iter.next().unwrap();
println!("{item2:?}");
println!("{item1:?}");
}If you're curious the output is because the buffer was overwritten. With a buffer size of 1K the output is |
|
A yes, indeed, my bad, should be reverted. I will open an issue to discuss the use of getdents outside of the iterator, to have more control on when the syscall is used (where the method takes a mut ref to buf so this situation can be caught by the borrow checker). |
See [this comment] for details. [this comment]: #1552 (comment)
|
I've now filed #1564 to revert this PR. I didn't add the testcase above because at a few brief tries I was unable to reproduce the failure. It appears dependent on the contents of the directory. |
|
@sunfishcode the test case isn't supposed to compile, so it'd be put in a doctest. |
|
It did compile, for me. |
|
Wat. Lemme play with it for a sec. |
|
I'm confused, it works fine? #1566 |
|
I could recreate the issue, with @SUPERCILEX example, changed a bit the buffer size (smaller) and reading 3 entries, it did override the first entries. |
The lifetime returned by
RawDir::next()is theRawDir's lifetime and not the buffer it uses ('buf). The file name lives inside the buffer provided to the kernel.Example
Without the change, the borrow checker will tell the following error:
The borrow checker passes with the change