Repository navigation
Fix NonNull::sub and NonNull::copy_* postconditions for zero-byte cases - #810
Open
fromtaoyuanhsinchuuuu wants to merge 1 commit into
Open
fromtaoyuanhsinchuuuu wants to merge 1 commit into
fromtaoyuanhsinchuuuu wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two specification gaps in
core::ptr::NonNullwhere#[ensures]postconditions failed on inputs admitted by their#[requires]preconditions and handled correctly by the method bodies:NonNull::sub: whenTis zero-sized,#[requires]permits anycount: usize, but#[ensures]evaluatedself.as_ptr().offset(-(count as isize)), overflowing whencount == isize::MIN as usize. Changed the postcondition to useself.as_ptr().wrapping_sub(count)(matchingNonNull::offset'swrapping_offsetpostcondition).NonNull::{copy_to, copy_to_nonoverlapping, copy_from, copy_from_nonoverlapping}:#[ensures]unconditionally assertedub_checks::can_dereference(... as *const u8)on both pointers even whencount == 0(e.g., one-past-the-end pointers) orsize_of::<T>() == 0(ZSTs). Guarded the 1-byte dereferenceability assertion withcount == 0 || core::mem::size_of::<T>() == 0.ptr::non_null::verifycovering ZSTNonNull::sub(includingisize::MIN as usize) as well as zero-count (one-past-the-end) and ZST calls for all fourNonNull::copy_*methods, verified with Kani (106harnesses passing,0failures).Resolves #801
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.