ringbahn / ringbahn

safe bindings to io-uring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect backwards seek?

evanrichter opened this issue · comments

https://github.com/withoutboats/ringbahn/blob/d3f7fb114495f0ac37398155b80000719741e1c7/src/fs.rs#L214-L216

I haven't tested this, but it seems like negative seek values are always made absolute then added to current position, instead of subtracting

Yes.. I'm trying to remember why I ever thought this was right, and i think I just blindly refactored it at some point into the incorrect code. It should be

if n >= 0 {
    *self.as_mut().pos() += n;
} else {
    *self.as_mut().pos() -= n.abs();
}

A PR would be welcome, or I could fix it.

I don't mind doing the Pr

should I do

*self.as_mut().pos().checked_sub(n.abs()).ok();

or something along those lines to return an error on negative seek values? AsyncSeek says seeking to a negative offset is considered an error. Perhaps futures_io::Error::InvalidInput (A parameter was incorrect)?

Yea, throwing an IO error on underflow would be great 👍. InvalidInput would be the same as what Linux lseek would return on a normal file, so that is correct.