elast0ny / shared_memory

A Rust wrapper around native shared memory for Linux and Windows
382 stars 51 forks source link

ShmemError Display impl contains infinite recursion #54

Closed defiori closed 3 years ago

defiori commented 3 years ago

This causes a stack overflow:

println!("{}", shared_memory::ShmemError::MapOpenFailed(0));

Running cargo expand on the quick_error! macro for ShmemError shows this

ShmemError::MapOpenFailed(ref err) => {
    let display_fn = |x: &ShmemError, f: &mut ::std::fmt::Formatter| {
        f.write_fmt(::core::fmt::Arguments::new_v1(
            &["", " : os error "],
            &match (&x, &err) {
                (arg0, arg1) => [
                    ::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Display::fmt),
                    ::core::fmt::ArgumentV1::new(arg1, ::core::fmt::Display::fmt),
                ],
            },
        ))
    };
    display_fn(self, fmt)
}

which seems to contain an infinite recursion, the Display impl for ShmemError calls itself.

elast0ny commented 3 years ago

Thanks for reporting this, definitely weird...

I see that quick_error had a new major release, maybe I will try switching to that or will just implement the errors manually.