Skip to content

Commit bfe1ab9

Browse files
KamilaBorowskaGankra
authored andcommitted
Clarify that str data must still be initialized
1 parent b8344ef commit bfe1ab9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/what-unsafe-does.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ language cares about is preventing the following things:
3030
* a `char` outside the ranges [0x0, 0xD7FF] and [0xE000, 0x10FFFF]
3131
* a `!` (all values are invalid for this type)
3232
* an integer (`i*`/`u*`), floating point value (`f*`), or raw pointer read from
33-
[uninitialized memory][]
33+
[uninitialized memory][], or uninitialized memory in a `str`.
3434
* a reference/`Box` that is dangling, unaligned, or points to an invalid value.
3535
* a wide reference, `Box`, or raw pointer that has invalid metadata:
3636
* `dyn Trait` metadata is invalid if it is not a pointer to a vtable for
@@ -48,11 +48,11 @@ A reference/pointer is "dangling" if it is null or not all of the bytes it
4848
points to are part of the same allocation (so in particular they all have to be
4949
part of *some* allocation). The span of bytes it points to is determined by the
5050
pointer value and the size of the pointee type. As a consequence, if the span is
51-
empty, "dangling" is the same as "non-null". Note that slices point to their
52-
entire range, so it's important that the length metadata is never too large
53-
(in particular, allocations and therefore slices cannot be bigger than
54-
`isize::MAX` bytes). If for some reason this is too cumbersome, consider using
55-
raw pointers.
51+
empty, "dangling" is the same as "non-null". Note that slices and strings point
52+
to their entire range, so it's important that the length metadata is never too
53+
large (in particular, allocations and therefore slices and strings cannot be
54+
bigger than `isize::MAX` bytes). If for some reason this is too cumbersome,
55+
consider using raw pointers.
5656

5757
That's it. That's all the causes of Undefined Behavior baked into Rust. Of
5858
course, unsafe functions and traits are free to declare arbitrary other

0 commit comments

Comments
 (0)