cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
504 stars 82 forks source link

"Pointee" used incorrectly to refer to the variable doing the pointing #105

Open KlausParanko opened 11 months ago

KlausParanko commented 11 months ago

URL to the section(s) of the book with this problem:

Description of the problem:

I believe there has been an error of thinking the word pointee refers to the variable doing the pointing (subject), rather than the thing being pointed to (object). In chapter 4, the sentence "undefined behavior: pointer used after its pointee is freed" is used in multiple of the diagrams showing how values/pointers in the stack and heap change. However, in some of the diagrams it is not the pointee (the data on the heap) that has been freed, but a variable pointing to the data.

example

Wiktionary's definition of pointee.

Suggested fix: Change "undefined behavior: pointer used after its pointee is freed" to "undefined behavior: pointer used after it has been freed" or "undefined behavior: pointer used after the pointing variable has been freed" in diagrams where the pointer is freed and the heap data remains.

willcrichton commented 11 months ago

To be clear, first itself is not freed. It is a stack variable, so its memory is still live. Its pointee, the heap string that used to contain "Ferris", has been freed. Hence the error message.