Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search panics with user-provided comparison function does not correctly implement a total order #448

Open
unexge opened this issue Jan 14, 2025 · 1 comment

Comments

@unexge
Copy link

unexge commented Jan 14, 2025

Time to time the search functionality (both triggered by ctrl + r or mcfly search) crashes with:

thread 'main' panicked at core/src/slice/sort/shared/smallsort.rs:860:5: user-provided comparison function does not correctly implement a total order

The panic comes from this part of the code: https://github.com/cantino/mcfly/blob/master/src/history/history.rs#L408-L449.

This is the stacktrace:

 $ thread 'main' panicked at core/src/slice/sort/shared/smallsort.rs:860:5:
user-provided comparison function does not correctly implement a total order
stack backtrace:
   0:        0x10019e3f0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::habbf9c4f641febb1
   1:        0x10007ccac - core::fmt::write::ha36a8060c13608ea
   2:        0x100177194 - std::io::Write::write_fmt::h431832c8ebcc85c9
   3:        0x1001a1ba8 - std::panicking::default_hook::h4ebc6eb4ae179807
   4:        0x1001a2ac0 - std::panicking::rust_panic_with_hook::h6a84efe4dcab239c
   5:        0x1001a1e18 - std::panicking::begin_panic_handler::{{closure}}::h5eef292190467fef
   6:        0x1001a1db4 - std::sys::backtrace::__rust_end_short_backtrace::hd7e7925203f20af9
   7:        0x1001a1da8 - _rust_begin_unwind
   8:        0x100327284 - core::panicking::panic_fmt::h410d3f147658259b
   9:        0x100327714 - core::slice::sort::shared::smallsort::panic_on_ord_violation::h839471df44ebe912
  10:        0x1000c91d4 - core::slice::sort::stable::quicksort::quicksort::h0facaa6d199e1507
  11:        0x1000d0c34 - core::slice::sort::stable::drift::sort::h9266b210b2e53b2e
  12:        0x1000d0ae4 - core::slice::sort::stable::driftsort_main::hbef73e36ca0d9fe9
  13:        0x1000a1b90 - mcfly::history::history::History::find_matches::hf20bc79d3d9c53d5
  14:        0x1000c3b14 - mcfly::interface::Interface::display::h3d4bd061a91b7141
  15:        0x100003e98 - mcfly::main::h10d8a17722a95eef
  16:        0x1000f0cac - std::sys::backtrace::__rust_begin_short_backtrace::h88a42488dd053506
  17:        0x1000093b4 - _main
Process 86147 exited with status = 101 (0x00000065)

And I was also able to get values that cause the crash, see this Rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c6dae2dc0d0e3d2788cd870c19c42ee7

I checked NaN values in the calculations and couldn't find any NaN value, and also verified that PartialOrd::partial_cmp at the end never falls to unwrap_or fallback. I suspect this is due to sort implementations in stdlib detecting incorrect Ord implementations and panicking in that case starting with Rust 1.81.

@cantino
Copy link
Owner

cantino commented Jan 25, 2025

Thanks @unexge! I've attempted a fix in #451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants