Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
dont increase the allocated size of vec (#10701)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi authored Jan 20, 2022
1 parent f318350 commit 48e0b41
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frame/support/src/storage/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,17 @@ impl<T, S: Get<u32>> BoundedVec<T, S> {
/// 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
}

Expand Down

0 comments on commit 48e0b41

Please sign in to comment.