Skip to content
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

Views on arrays should become views on a slice of the Memory that was accssible at view construction #54435

Open
gbaraldi opened this issue May 10, 2024 · 1 comment
Labels
domain:arrays [a, r, r, a, y, s]

Comments

@gbaraldi
Copy link
Member

This has historically being a possible unchecked OOB access if a user made a vector and pushed/popped/sizehinted it while keeping a view into the array. Views do not do a double boundscheck (one on the view and one on the array), instead they boundscheck on their bounds and perform a check during view construction that all of their indices are valid. Before we had array this was an issue with no clean solution, we either do the double boundscheck or have what we have right now which is potential OOB. With Memory we can have the view ignore the array and turn that OOB/UB into defined code, because Memory bounds nevert change. This has a caveat that it now means if someone pushes/pops that vector while keeping a view, the view may no longer alias the array.

@sgaure
Copy link

sgaure commented May 10, 2024

Wouldn't it still be possible with OOB?

v = rand(4)
ii = [1,2,3]
vv = view(v, ii)
push!(ii, 42)
vv[4]

@nsajko nsajko added the domain:arrays [a, r, r, a, y, s] label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests

3 participants