diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/arrayvec/src/array_string.rs | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/arrayvec/src/array_string.rs')
-rw-r--r-- | vendor/arrayvec/src/array_string.rs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/vendor/arrayvec/src/array_string.rs b/vendor/arrayvec/src/array_string.rs index c4712a0cb..90cfc0901 100644 --- a/vendor/arrayvec/src/array_string.rs +++ b/vendor/arrayvec/src/array_string.rs @@ -1,4 +1,4 @@ -use std::borrow::Borrow; +use std::borrow::{Borrow, BorrowMut}; use std::cmp; use std::convert::TryFrom; use std::fmt; @@ -201,6 +201,7 @@ impl<const CAP: usize> ArrayString<CAP> /// /// assert_eq!(&string[..], "ab"); /// ``` + #[track_caller] pub fn push(&mut self, c: char) { self.try_push(c).unwrap(); } @@ -252,6 +253,7 @@ impl<const CAP: usize> ArrayString<CAP> /// /// assert_eq!(&string[..], "ad"); /// ``` + #[track_caller] pub fn push_str(&mut self, s: &str) { self.try_push_str(s).unwrap() } @@ -371,10 +373,12 @@ impl<const CAP: usize> ArrayString<CAP> let next = idx + ch.len_utf8(); let len = self.len(); + let ptr = self.as_mut_ptr(); unsafe { - ptr::copy(self.as_ptr().add(next), - self.as_mut_ptr().add(idx), - len - next); + ptr::copy( + ptr.add(next), + ptr.add(idx), + len - next); self.set_len(len - (next - idx)); } ch @@ -479,6 +483,11 @@ impl<const CAP: usize> Borrow<str> for ArrayString<CAP> fn borrow(&self) -> &str { self } } +impl<const CAP: usize> BorrowMut<str> for ArrayString<CAP> +{ + fn borrow_mut(&mut self) -> &mut str { self } +} + impl<const CAP: usize> AsRef<str> for ArrayString<CAP> { fn as_ref(&self) -> &str { self } @@ -638,3 +647,27 @@ impl<'a, const CAP: usize> TryFrom<fmt::Arguments<'a>> for ArrayString<CAP> Ok(v) } } + +#[cfg(feature = "zeroize")] +/// "Best efforts" zeroing of the `ArrayString`'s buffer when the `zeroize` feature is enabled. +/// +/// The length is set to 0, and the buffer is dropped and zeroized. +/// Cannot ensure that previous moves of the `ArrayString` did not leave values on the stack. +/// +/// ``` +/// use arrayvec::ArrayString; +/// use zeroize::Zeroize; +/// let mut string = ArrayString::<6>::from("foobar").unwrap(); +/// string.zeroize(); +/// assert_eq!(string.len(), 0); +/// unsafe { string.set_len(string.capacity()) }; +/// assert_eq!(&*string, "\0\0\0\0\0\0"); +/// ``` +impl<const CAP: usize> zeroize::Zeroize for ArrayString<CAP> { + fn zeroize(&mut self) { + // There are no elements to drop + self.clear(); + // Zeroize the backing array. + self.xs.zeroize(); + } +} |