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

Fix note about undefined behavior #2632

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

randomPoison
Copy link
Collaborator

So turns out this example does trigger undefined behavior. It's undefined behavior to use a pointer to read past the end of the object from which the pointer was originally created. So even though we know there's another array past the end of the first one, it's still undefined behavior to read past the end of the array if we created the initial pointer from the first array. You can see this if you run miri in the playground. If we tweak the example to instead take a pointer to the struct as a whole it runs through miri with no errors, since now we're allowed to read the full contents of the struct.

Isn't undefined behavior fun? 🙃

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.

2 participants