Skip to content

Commit 0553235

Browse files
blueglyphredglyph
and
redglyph
authored
Fix typos and grammatical errors (#384)
Co-authored-by: redglyph <redglyph@localhost>
1 parent 9c73283 commit 0553235

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/unchecked-uninit.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Unsafe Rust gives us a powerful tool to handle this problem:
1111
[`MaybeUninit`]. This type can be used to handle memory that has not been fully
1212
initialized yet.
1313

14-
With `MaybeUninit`, we can initialize an array element-for-element as follows:
14+
With `MaybeUninit`, we can initialize an array element by element as follows:
1515

1616
```rust
1717
use std::mem::{self, MaybeUninit};
@@ -79,16 +79,15 @@ This code proceeds in three steps:
7979
acknowledge that by providing appropriate methods).
8080

8181
It's worth spending a bit more time on the loop in the middle, and in particular
82-
the assignment operator and its interaction with `drop`. If we would have
83-
written something like:
82+
the assignment operator and its interaction with `drop`. If we wrote something like:
8483

8584
<!-- ignore: simplified code -->
8685
```rust,ignore
8786
*x[i].as_mut_ptr() = Box::new(i as u32); // WRONG!
8887
```
8988

9089
we would actually overwrite a `Box<u32>`, leading to `drop` of uninitialized
91-
data, which will cause much sadness and pain.
90+
data, which would cause much sadness and pain.
9291

9392
The correct alternative, if for some reason we cannot use `MaybeUninit::new`, is
9493
to use the [`ptr`] module. In particular, it provides three functions that allow
@@ -97,16 +96,16 @@ us to assign bytes to a location in memory without dropping the old value:
9796

9897
* `ptr::write(ptr, val)` takes a `val` and moves it into the address pointed
9998
to by `ptr`.
100-
* `ptr::copy(src, dest, count)` copies the bits that `count` T's would occupy
99+
* `ptr::copy(src, dest, count)` copies the bits that `count` T items would occupy
101100
from src to dest. (this is equivalent to C's memmove -- note that the argument
102101
order is reversed!)
103102
* `ptr::copy_nonoverlapping(src, dest, count)` does what `copy` does, but a
104103
little faster on the assumption that the two ranges of memory don't overlap.
105104
(this is equivalent to C's memcpy -- note that the argument order is reversed!)
106105

107106
It should go without saying that these functions, if misused, will cause serious
108-
havoc or just straight up Undefined Behavior. The only things that these
109-
functions *themselves* require is that the locations you want to read and write
107+
havoc or just straight up Undefined Behavior. The only requirement of these
108+
functions *themselves* is that the locations you want to read and write
110109
are allocated and properly aligned. However, the ways writing arbitrary bits to
111110
arbitrary locations of memory can break things are basically uncountable!
112111

0 commit comments

Comments
 (0)