From 7c91d009c112ff8c68cb459b2807231bedf1fbaa Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 2 Mar 2023 16:29:49 +0100 Subject: [PATCH] reader: Remove assert in history search This isn't a great use of `assert` because it turns a benign "oh I need to search again" bug into a crash. Fixes #9628 --- src/reader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 6c4b40d5a..3f9b3ce35 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -429,8 +429,15 @@ class reader_history_search_t { const wcstring &needle = search_string(); if (mode_ == line || mode_ == prefix) { size_t offset = find(text, needle); - assert(offset != wcstring::npos && "Should have found a match in the search result"); - add_if_new({std::move(text), offset}); + // FIXME: Previous versions asserted out if this wasn't true. + // This could be hit with a needle of "ö" and haystack of "echo Ö" + // I'm not sure why - this points to a bug in ifind (probably wrong locale?) + // However, because the user experience of having it crash is horrible, + // and the worst thing that can otherwise happen here is that a search is unsuccessful, + // we just check it instead. + if (offset != wcstring::npos) { + add_if_new({std::move(text), offset}); + } } else if (mode_ == token) { auto tok = new_tokenizer(text.c_str(), TOK_ACCEPT_UNFINISHED);