Skip to content

Conversation

@gdennie
Copy link

@gdennie gdennie commented Oct 19, 2023

made the language around immutable target of references more direct

made the language around immutable target of references more direct
verifying that references don't escape the scope of their referent. That's
because ensuring pointers are always valid is much more complicated than this.
Of course, Rust's story around ownership is much more complicated than simply
gauranteeing that references cannot outlive their target. That is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gauranteeing that references cannot outlive their target. That is
guaranteeing that references cannot outlive their target. That is

referent and its owners.
a naive scope analysis would be insufficient to prevent this bug because `data`
does indeed live as long as required. However, `data` is *changed* by `push(4)`
and now may have been realocated to accommodate the new value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and now may have been realocated to accommodate the new value.
and now may have been reallocated to accommodate the new value.

Comment on lines +65 to +66
Consequently, `x` may now be referring to the old
value or memory already put to use in another process (pre-emptive multi-tasking).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going into detail this far (another process & preemptive multitasking) is misleading in multiple ways:

  • the actual issue of accessing free'd memory is not mentioned
  • accessing free'd memory is UB
  • another process & preemptive multitasking is not a requirement
Suggested change
Consequently, `x` may now be referring to the old
value or memory already put to use in another process (pre-emptive multi-tasking).
Consequently, the memory location pointed to by `x` may now be free'd and therefore any attempt to dereference `x` is UB.

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