Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iter::slice_skip remove possibility of underflow in debug_assert #187

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

hkBst
Copy link
Contributor

@hkBst hkBst commented Oct 22, 2024

self.cursor.sub(skip) must point inside the allocation of this object or this is UB, not to mention the possibility that if skip is very large self.cursor.sub(skip) may underflow and fail to trigger the debug_assertion.

@hkBst
Copy link
Contributor Author

hkBst commented Oct 22, 2024

Apparently offset_from stabilized in 1.47.0 (35 versions behind 1.82.0 times 6 weeks is 210 weeks or about 4 years old) is too new as MSRV=1.36. It "is equivalent to (self as isize - origin as isize) / (mem::size_of::() as isize), except that it has a lot more opportunities for UB, in exchange for the compiler better understanding what you are doing.", but I suppose I can make that work if you really still care about 1.36...

`self.cursor.sub(skip)` must point inside the allocation of this object or this is UB, not to mention the possibility that if `skip` if very large self.cursor.sub(skip) may underflow and fail to trigger the debug_assertion.
@hkBst
Copy link
Contributor Author

hkBst commented Dec 6, 2024

MSRV is now 1.47.0, and this patch now passes all checks. There should not be any performance impact, since this only changes a debug_assert.

@seanmonstar seanmonstar merged commit 380f130 into seanmonstar:master Dec 6, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants