Skip to content

vec: Fix size_hint() of reverse iterators #7565

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

Merged
merged 1 commit into from
Jul 4, 2013
Merged

vec: Fix size_hint() of reverse iterators #7565

merged 1 commit into from
Jul 4, 2013

Conversation

Blei
Copy link
Contributor

@Blei Blei commented Jul 3, 2013

Fixes #7558

@alexcrichton
Copy link
Member

There's also the separate problem of why does this fix the problem? Rust isn't a language that should segfault because of a bug in an implementation. Does this happen because a negative int is casted to an unsigned int?

@bluss
Copy link
Member

bluss commented Jul 4, 2013

@alexcrichton this testcase has a similar crash, no overflow checking in ~[]::reserve.

fn main() {
    let mut v = ~[];
    v.reserve(-1);
    v.push(1);
    v.push(2);
}
// *** glibc detected *** ./crash~: free(): invalid next size (fast): 0x00000000022e9040 ***

@alexcrichton
Copy link
Member

Yes, but I meant that this bug should be fixed as well as that one: #7578

thestinger added a commit that referenced this pull request Jul 4, 2013
vec: Fix size_hint() of reverse iterators
@thestinger thestinger merged commit dd4f6bb into rust-lang:master Jul 4, 2013
@Blei Blei deleted the fix-rev-size-hint branch July 4, 2013 09:18
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 3, 2021
New lint `manual_split_once`

This is a WIP because it still needs to recognize more patterns. Currently handles:

```rust
s.splitn(2, ' ').next();
s.splitn(2, ' ').nth(0)
s.splitn(2, ' ').nth(1);
s.splitn(2, ' ').skip(0).next();
s.splitn(2, ' ').skip(1).next();
s.splitn(2, ' ').next_tuple(); // from itertools

// as well as `unwrap()` and `?` forms
```

Still to do:

```rust
let mut iter = s.splitn(2, ' ');
(iter.next().unwrap(), iter.next()?)

let mut iter = s.splitn(2, ' ');
let key = iter.next().unwrap();
let value = iter.next()?;
```

Suggestions on other patterns to check for would be useful. I've done a search on github for uses of `splitn`. Still have yet to actually look through the results.

There's also the question of whether the lint shouold trigger on all uses of `splitn` with two values, or only on recognized usages. The former could have false positives where it couldn't be replaced, but I'm not sure how common that would be.

changelog: Add lint `manual_split_once`
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.

vec.rev_iter().collect() causes memory corruption
5 participants