Skip to content

Commit 37a952a

Browse files
committed
Fixed build error as per steveklabnik's suggestion and expanded on the ills of doing out of bounds accesses.
1 parent a6fedc8 commit 37a952a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/doc/book/ownership.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ Rust’s safety guarantees by introducing a data race if one could access both
166166
For example if we truncated the vector to just two elements through `v2`:
167167

168168
```rust
169+
# let v = vec![1, 2, 3];
170+
# let v2 = v;
169171
v2.truncate(2);
170172
```
171173

@@ -174,7 +176,9 @@ would not know that the heap data has been truncated. Now, the part of the
174176
vector `v1` on the stack does not agree with the corresponding part on the
175177
heap. `v1` still thinks there are three elements in the vector and will
176178
happily let us access the non existent element `v1[2]` but as you might
177-
already know this is a recipe for disaster (might lead to a segfault).
179+
already know this is a recipe for disaster. Especially because it might lead
180+
to a segmentation fault or worse allow an unauthorized user to read from
181+
memory to which they don't have access.
178182

179183
This is why Rust forbids using `v` after we’ve done the move.
180184

0 commit comments

Comments
 (0)