-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Account for possible 0-sized elements in vector iterators #7738
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
Conversation
I don't think this is the right solution because it will have runtime overhead. It really just needs to be a pointer compare and a pointer addition, rather than 3 operations. It's possible it could be solved by making a There are also some other broken things (not just iterators) like slices. It seems like fixed-size arrays might have other problems too. |
I believe that slices are correct. They use Fixed-size arrays also don't appear to be wrong. Their actual size may be questionable, but the iteration works just fine over them. I'm not quite comfortable with a If we used a Also, I don't think that anyone else should seriously be using a |
@alexcrichton: they're definitely wrong, the case I reported in the bug is with a slice |
I specifically added a test for the case you mentioned, and it passes. As in in this request they're fixed, but it wasn't anything wrong with the slice, it was just the iterator. |
Ah, I see what you mean, I didn't realize |
repr was actually fixed previously (6d4d2c9) |
@alexcrichton: I'm not really understanding why |
Oh good point, are you sure you're using the most recent version of the compiler? Turns out the iterators are just another issue. |
@alexcrichton: I'm at |
It should...
|
With your test:
|
Huh, that's weird. My version is 02adf6c which is this commit + some extras. This should definitely be working on linux because there's a test at the end of I'm building the current master right now, there's definitely something odd going on... |
For anyone else looking at this, we narrowed it down on IRC to also being caused by iterators. It's confusing having two implementations of |
If 0-sized element dereferencing doesn't read memory, then we're safe. We already figured out that pointers to zero-sized structs are just kinda pointers to nothing, so I think that this is OK. |
Landing with #7736. |
Closes #7733