From: Robert Obkircher <r.obkircher@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH v1 proxmox 6/6] io: remove unused ByteVecExt trait with grow_ and resize_uninitialized
Date: Tue, 11 Aug 2026 17:02:05 +0200 [thread overview]
Message-ID: <20260811150237.527116-7-r.obkircher@proxmox.com> (raw)
In-Reply-To: <20260811150237.527116-1-r.obkircher@proxmox.com>
These methods appear to be unused now, and in cases where dealing with
uninitialized memory is necessary, it would be more appropriate to use
safer methods like Vec::spare_capacity_mut.
Signed-off-by: Robert Obkircher <r.obkircher@proxmox.com>
---
proxmox-io/src/vec/byte_vec.rs | 101 ---------------------------------
proxmox-io/src/vec/mod.rs | 9 +--
2 files changed, 1 insertion(+), 109 deletions(-)
delete mode 100644 proxmox-io/src/vec/byte_vec.rs
diff --git a/proxmox-io/src/vec/byte_vec.rs b/proxmox-io/src/vec/byte_vec.rs
deleted file mode 100644
index 0a45ba0a..00000000
--- a/proxmox-io/src/vec/byte_vec.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-//! This module provides additional operations for `Vec<u8>`.
-//!
-//! Example:
-//! ```
-//! # use std::io::Read;
-//! use proxmox_io::vec::{self, ByteVecExt};
-//!
-//! fn append_1024_to_vec<T: Read>(mut input: T, buffer: &mut Vec<u8>) -> std::io::Result<()> {
-//! input.read_exact(unsafe { buffer.grow_uninitialized(1024) })
-//! }
-//! ```
-
-/// Some additional byte vector operations useful for I/O code.
-/// Example:
-/// ```
-/// # use std::io::Read;
-/// # use proxmox_io::ReadExt;
-/// use proxmox_io::vec::{self, ByteVecExt};
-///
-/// # fn code(mut file: std::fs::File, mut data: Vec<u8>) -> std::io::Result<()> {
-/// file.read_exact(unsafe {
-/// data.grow_uninitialized(1024)
-/// })?;
-/// # Ok(())
-/// # }
-/// ```
-///
-/// [`ReadExt`]: crate::ReadExt
-pub trait ByteVecExt {
- /// Grow a vector without initializing its elements. The difference to simply using `reserve`
- /// is that it also updates the actual length, making the newly allocated data part of the
- /// slice.
- ///
- /// This is a shortcut for:
- /// ```ignore
- /// vec.reserve(more);
- /// let total = vec.len() + more;
- /// unsafe {
- /// vec.set_len(total);
- /// }
- /// ```
- ///
- /// This returns a mutable slice to the newly allocated space, so it can be used inline:
- /// ```
- /// # use std::io::Read;
- /// # use proxmox_io::vec::ByteVecExt;
- /// # fn test(mut file: std::fs::File, buffer: &mut Vec<u8>) -> std::io::Result<()> {
- /// file.read_exact(unsafe { buffer.grow_uninitialized(1024) })?;
- /// # Ok(())
- /// # }
- /// ```
- ///
- /// # Safety
- ///
- /// When increasing the size, the new contents are uninitialized and have nothing to do with
- /// the previously contained content. Since we cannot track this state through the type system,
- /// this method is marked as an unsafe API for good measure.
- ///
- /// [`ReadExt`]: crate::ReadExt
- unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8];
-
- /// Resize a vector to a specific size without initializing its data. This is a shortcut for:
- /// ```ignore
- /// if new_size <= vec.len() {
- /// vec.truncate(new_size);
- /// } else {
- /// unsafe {
- /// vec.grow_uninitialized(new_size - vec.len());
- /// }
- /// }
- /// ```
- ///
- /// # Safety
- ///
- /// When increasing the size, the new contents are uninitialized and have nothing to do with
- /// the previously contained content. Since we cannot track this state through the type system,
- /// this method is marked as an unsafe API for good measure.
- unsafe fn resize_uninitialized(&mut self, total: usize);
-}
-
-impl ByteVecExt for Vec<u8> {
- unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8] {
- let old_len = self.len();
- self.reserve(more);
- let total = old_len + more;
- unsafe {
- self.set_len(total);
- }
- &mut self[old_len..]
- }
-
- unsafe fn resize_uninitialized(&mut self, new_size: usize) {
- if new_size <= self.len() {
- self.truncate(new_size);
- } else {
- unsafe {
- self.grow_uninitialized(new_size - self.len());
- }
- }
- }
-}
diff --git a/proxmox-io/src/vec/mod.rs b/proxmox-io/src/vec/mod.rs
index e4cc9892..94f87735 100644
--- a/proxmox-io/src/vec/mod.rs
+++ b/proxmox-io/src/vec/mod.rs
@@ -17,7 +17,7 @@
//!
//! Examples:
//! ```no_run
-//! use proxmox_io::vec::{self, ByteVecExt};
+//! use proxmox_io::vec;
//!
//! # let size = 64usize;
//! # let more = 64usize;
@@ -25,15 +25,8 @@
//!
//! let mut buffer = unsafe { vec::uninitialized(size) }; // an actually uninitialized buffer
//! vec::clear(&mut buffer); // zero out an &mut [u8]
-//!
-//! vec::clear(unsafe {
-//! buffer.grow_uninitialized(more) // grow the buffer with uninitialized bytes
-//! });
//! ```
-mod byte_vec;
-pub use byte_vec::ByteVecExt;
-
/// Create an uninitialized byte vector of a specific size.
///
/// This is just a shortcut for:
--
2.47.3
prev parent reply other threads:[~2026-08-11 15:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 15:01 [PATCH v1 proxmox 0/6] uninitialized memory allocations fixes Robert Obkircher
2026-08-11 15:02 ` [PATCH v1 proxmox 1/6] uuid: avoid potential null dereference and memory leaks Robert Obkircher
2026-08-11 15:02 ` [PATCH v1 proxmox 2/6] io: request zeroed memory instead of manually clearing it Robert Obkircher
2026-08-11 15:02 ` [PATCH v1 proxmox 3/6] io: avoid potential null dereference and memory leak on error path Robert Obkircher
2026-08-11 15:02 ` [PATCH v1 proxmox 4/6] io: remove boxed::uninitialized because it is unsound Robert Obkircher
2026-08-11 15:02 ` [PATCH v1 proxmox 5/6] io: remove unused append_to_vec functions Robert Obkircher
2026-08-11 15:02 ` Robert Obkircher [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260811150237.527116-7-r.obkircher@proxmox.com \
--to=r.obkircher@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox