From 48e0b415b94d8ce14e0ebbbdb813263afa27f02e Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 20 Jan 2022 14:17:16 -0400 Subject: [PATCH] dont increase the allocated size of vec (#10701) --- frame/support/src/storage/bounded_vec.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frame/support/src/storage/bounded_vec.rs b/frame/support/src/storage/bounded_vec.rs index 6d7206df6db10..6b20ed2bba90f 100644 --- a/frame/support/src/storage/bounded_vec.rs +++ b/frame/support/src/storage/bounded_vec.rs @@ -222,16 +222,17 @@ impl> BoundedVec { /// Returns `true` if the item was inserted. pub fn force_insert_keep_left(&mut self, index: usize, element: T) -> bool { // Check against panics. - if Self::bound() < index || self.len() < index { + if Self::bound() < index || self.len() < index || Self::bound() == 0 { return false } // Noop condition. if Self::bound() == index && self.len() <= Self::bound() { return false } - // Cannot panic since self.len() >= index; + // Cannot panic since `Self.bound() > 0` + self.0.truncate(Self::bound() - 1); + // Cannot panic since `self.len() >= index`; self.0.insert(index, element); - self.0.truncate(Self::bound()); true }