Fill the unwritten tail of `buf` with zero bytes so an O_DIRECT write of the entire aligned slot does not leak stale buffer contents to disk.
(buf: &mut AlignedBuf)
| 420 | /// Fill the unwritten tail of `buf` with zero bytes so an O_DIRECT write of |
| 421 | /// the entire aligned slot does not leak stale buffer contents to disk. |
| 422 | fn zero_tail(buf: &mut AlignedBuf) { |
| 423 | let written = buf.len(); |
| 424 | let cap = buf.capacity(); |
| 425 | if written < cap { |
| 426 | // SAFETY: `as_mut_ptr` is valid for `capacity` bytes; we write only |
| 427 | // the uninitialized tail between `written..capacity`. |
| 428 | unsafe { |
| 429 | std::ptr::write_bytes(buf.as_mut_ptr().add(written), 0, cap - written); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /// View the entire allocated capacity of `buf` as a byte slice. Requires |
| 435 | /// that the caller has zeroed any unwritten tail (see `zero_tail`). |
no test coverage detected