[pve-devel] [PATCH proxmox-backup 7/9] tools/lru_cache: make minimum capacity 1

Stefan Reiter s.reiter at proxmox.com
Wed Jun 2 16:38:31 CEST 2021


Setting this to 0 is not just useless, but breaks the logic horribly
enough to cause random segfaults - better forbid this, to avoid someone
else having to debug it again ;)

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 src/tools/lru_cache.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/tools/lru_cache.rs b/src/tools/lru_cache.rs
index 70289d3f..7c8cf25f 100644
--- a/src/tools/lru_cache.rs
+++ b/src/tools/lru_cache.rs
@@ -106,6 +106,7 @@ unsafe impl<K: Send, V: Send> Send for LruCache<K, V> {}
 impl<K: std::cmp::Eq + std::hash::Hash + Copy, V> LruCache<K, V> {
     /// Create LRU cache instance which holds up to `capacity` nodes at once.
     pub fn new(capacity: usize) -> Self {
+        let capacity = capacity.min(1);
         Self {
             map: HashMap::with_capacity(capacity),
             list: LinkedList::new(),
-- 
2.30.2






More information about the pve-devel mailing list