You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BusyBeaver-42 opened this issue
Jan 24, 2025
· 0 comments
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.
The SAFETY comment in question is located in the merge_down function in the smallsort module in shared in sort in the slice module of the core crate.
Summary
While working on the Rust std-lib verification, I identified a missing requirement in the SAFETY comment in the merge_down function in the smallsort module.
Description of the problem
In the following code, the SAFETY comment does not guarantee that dst.sub(1) remains within the same allocated object as dst. This violates one of the safety requirements for pointer.sub.
unsafefnmerge_down<T,F:FnMut(&T,&T) -> bool>(mutleft_src:*constT,mutright_src:*constT,mutdst:*mutT,is_less:&mutF,) -> (*constT,*constT,*mutT){// snip// SAFETY: The caller must guarantee that `left_src`, `right_src` are valid// to read and `dst` is valid to write, while not aliasing.unsafe{// snip
dst = dst.sub(1);// <- issue here}(left_src, right_src, dst)}
Proposed fix
Update the SAFETY comment as follows.
// SAFETY: The caller must guarantee that `left_src`, `right_src` are valid
- // to read and `dst` is valid to write, while not aliasing.+ // to read, `dst` is valid to write, while not aliasing, and `dst.sub(1)`+ // is within the same allocated object as `dst`.
merge_up does not have the same problem
Although the SAFETY comment in the merge_up function may appear to have a similar issue, I believe this is not the case. Since dst must already be valid for a write, dst.add(1) will remain within the bounds of the same allocated object.
The text was updated successfully, but these errors were encountered:
BusyBeaver-42
added
the
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
label
Jan 24, 2025
jieyouxu
added
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
and removed
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Jan 26, 2025
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.
Location
The SAFETY comment in question is located in the
merge_down
function in thesmallsort
module inshared
insort
in theslice
module of thecore
crate.Summary
While working on the Rust std-lib verification, I identified a missing requirement in the SAFETY comment in the
merge_down
function in thesmallsort
module.Description of the problem
In the following code, the SAFETY comment does not guarantee that
dst.sub(1)
remains within the same allocated object asdst
. This violates one of the safety requirements forpointer.sub
.Proposed fix
Update the SAFETY comment as follows.
merge_up
does not have the same problemAlthough the SAFETY comment in the
merge_up
function may appear to have a similar issue, I believe this is not the case. Sincedst
must already be valid for a write,dst.add(1)
will remain within the bounds of the same allocated object.The text was updated successfully, but these errors were encountered: