Skip to content

Off by one error in str::index_mut (specifically) for RangeToInclusive (specifically) #50002

Closed

Description

@ExpHP

Caught while fleshing out a much beefier test suite for SliceIndex, which I plan to submit as a PR. (this Issue is here just in case that PR never happens).

rust/src/libcore/str/mod.rs

Lines 2107 to 2115 in 1ef1563

fn index_mut(self, slice: &mut str) -> &mut Self::Output {
assert!(self.end != usize::max_value(),
"attempted to index str up to maximum usize");
if slice.is_char_boundary(self.end) {
unsafe { self.get_unchecked_mut(slice) }
} else {
super::slice_error_fail(slice, 0, self.end + 1)
}
}

The unicode character boundary check here should be looking at self.end + 1. Better yet, the method could just delegate to RangeTo instead. (note: it can't delegate to get_mut here without NLL, which seems to be a leading factor as to how this function ended up this way)

Activity

  1. changed the title [-]Off by one error in str::get_mut (specifically) for RangeToInclusive (specifically)[/-] [+]Off by one error in str::index_mut (specifically) for RangeToInclusive (specifically)[/+] on Apr 16, 2018
  2. added this to the 1.26 milestone on Apr 21, 2018
  3. alexcrichton commented on Apr 21, 2018

    @alexcrichton
    Member

    Not technically a regression but tagging it as such to ensure that we don't forget about it.

  4. added a commit that references this issue on Apr 21, 2018
    699eb95
  5. ExpHP commented on Apr 21, 2018

    @ExpHP
    ContributorAuthor

    @alexcrichton my commit message accidentally closed this, which might defeat the purpose of the tag you added

    (note: I myself can't reopen it because Github attributed the message to Bors)

  6. alexcrichton commented on Apr 21, 2018

    @alexcrichton
    Member

    Oh that's ok, the tags on the PR take over now for backporting and that's how we'll track this.

  7. added a commit that references this issue on Apr 23, 2018
    7ef7f38
  8. ExpHP commented on May 10, 2018

    @ExpHP
    ContributorAuthor

    (ahhhh, now I see. The tag is used in automation for a Github Project to track regressions. That's actually pretty cool!)

    (...don't mind me, just talking to myself)

  9. added a commit that references this issue on May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-api[DEPRECATED; DO NOT USE]regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions