From 059804612a469e6ea6409be38e36c32f7a173187 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 4 Jan 2019 08:45:53 +0100 Subject: [PATCH] string: Fix crash with _GLIBCXX_ASSERTIONS This asserted because we accessed wcstring::front() when it was empty. Instead, check explicitly for it being empty before. Fixes #5479 --- src/builtin_string.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index 6e810a32e..bbc7e40c0 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -622,9 +622,13 @@ class wildcard_matcher_t : public string_matcher_t { } } if (opts.entire) { - // If the pattern is empty, this becomes one ANY_STRING that matches everything. - if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING); - if (wcpattern.back() != ANY_STRING) wcpattern.push_back(ANY_STRING); + if (!wcpattern.empty()) { + if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING); + if (wcpattern.back() != ANY_STRING) wcpattern.push_back(ANY_STRING); + } else { + // If the pattern is empty, this becomes one ANY_STRING that matches everything. + wcpattern.push_back(ANY_STRING); + } } }