rkuhn / acto

Actor library for Rust
25 stars 2 forks source link

panic in actor.rs:write_id #7

Closed rkuhn closed 2 months ago

rkuhn commented 2 months ago

---- file::gc_file_partial stdout ---- thread 'file::gc_file_partial' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/acto-0.7.0/src/actor.rs:748:28: attempt to shift right with overflow

Here it is:

fn write_id(buf: &mut [u8; 16], id: ActoId) -> &str {
    let id = id.0;
    if id == 0 {
        return "0";
    }
    let mut written = 0;
    let mut shift = (16 - (id.leading_zeros()) / 4) * 4;
    while shift != 0 {
        shift -= 4;
        const HEX: [u8; 16] = *b"0123456789abcdef";
        buf[written] = HEX[(id >> shift) & 15]; // <<<<<<<<<<<<<<<<<<<<<<<<<<<
        written += 1;
    }
    unsafe { std::str::from_utf8_unchecked(&buf[..written]) }
}

(thanks @rklaehn for identifying this!)

rkuhn commented 2 months ago

fixed in 0.7.1