contain-rs / lru-cache

A cache that holds a limited number of key-value pairs
https://contain-rs.github.io/lru-cache/lru_cache/
Apache License 2.0
83 stars 36 forks source link

Please consider fixing the linked-hash-map minimal version to at least 0.5.3 #50

Closed paullgdc closed 2 years ago

paullgdc commented 3 years ago

Issue

use lru_cache::LruCache;

fn main() {}

#[test]
fn test_panics() {
    let mut l = LruCache::new(10);
    l.insert(1, false);
}
cargo test

This code panics when the linked-hash-map crate used by lru_cache is under version 0.5.3, because it contains uninitialized memory allocation. The uninitialized memory problem seems to be fixed for version 0.5.3, but because the dependency is specified in Cargo.toml as

linked-hash-map = "0.5"

It means that cargo is free to choose any version >=0.5.0, and if the 0.5.1 or 0.5.2 versions are present in the local package cache, they might be picked.

Rewriting it instead as

linked-hash-map = "0.5.3"

and releasing it as new minor version 0.1.3 would fix the problem, as cargo would be forced to pick a version >=0.5.3