Skip to content

Commit 00b13b0

Browse files
committed
clarify UB for raw ptr deref
1 parent c164fb7 commit 00b13b0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/behavior-considered-undefined.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ code.
2323
</div>
2424

2525
* Data races.
26-
* Dereferencing (using the `*` operator on) a dangling or unaligned raw pointer.
26+
* Evaluating a dereference [place expression] (`*expr`) on a raw pointer that is
27+
[dangling] or unaligned.
2728
* Breaking the [pointer aliasing rules]. `&mut T` and `&T` follow LLVM’s scoped
2829
[noalias] model, except if the `&T` contains an [`UnsafeCell<U>`].
2930
* Mutating immutable data. All data inside a [`const`] item is immutable. Moreover, all
@@ -45,7 +46,7 @@ code.
4546
* A `!` (all values are invalid for this type).
4647
* An integer (`i*`/`u*`), floating point value (`f*`), or raw pointer obtained
4748
from [uninitialized memory][undef], or uninitialized memory in a `str`.
48-
* A reference or `Box<T>` that is dangling, unaligned, or points to an invalid value.
49+
* A reference or `Box<T>` that is [dangling], unaligned, or points to an invalid value.
4950
* Invalid metadata in a wide reference, `Box<T>`, or raw pointer:
5051
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for
5152
`Trait` that matches the actual dynamic trait the pointer or reference points to.
@@ -62,6 +63,17 @@ a restricted set of valid values. In other words, the only cases in which
6263
reading uninitialized memory is permitted are inside `union`s and in "padding"
6364
(the gaps between the fields/elements of a type).
6465

66+
> **Note**: Undefined behavior affects the entire program. For example, calling
67+
> a function in C that exhibits undefined behavior of C means your entire
68+
> program contains undefined behaviour that can also affect the Rust code. And
69+
> vice versa, undefined behavior in Rust can cause adverse affects on code
70+
> executed by any FFI calls to other languages.
71+
72+
[place expression]: expressions.md#place-expressions-and-value-expressions
73+
74+
### Dangling pointers
75+
[dangling]: #dangling-pointers
76+
6577
A reference/pointer is "dangling" if it is null or not all of the bytes it
6678
points to are part of the same allocation (so in particular they all have to be
6779
part of *some* allocation). The span of bytes it points to is determined by the
@@ -71,12 +83,6 @@ that slices and strings point to their entire range, so it is important that the
7183
metadata is never too large. In particular, allocations and therefore slices and strings
7284
cannot be bigger than `isize::MAX` bytes.
7385

74-
> **Note**: Undefined behavior affects the entire program. For example, calling
75-
> a function in C that exhibits undefined behavior of C means your entire
76-
> program contains undefined behaviour that can also affect the Rust code. And
77-
> vice versa, undefined behavior in Rust can cause adverse affects on code
78-
> executed by any FFI calls to other languages.
79-
8086
[`bool`]: types/boolean.md
8187
[`const`]: items/constant-items.md
8288
[noalias]: http://llvm.org/docs/LangRef.html#noalias

0 commit comments

Comments
 (0)