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
This commit is contained in:
Fabian Homborg 2019-01-04 08:45:53 +01:00 committed by ridiculousfish
parent 028bff7b44
commit 059804612a

View File

@ -622,9 +622,13 @@ class wildcard_matcher_t : public string_matcher_t {
} }
} }
if (opts.entire) { if (opts.entire) {
// If the pattern is empty, this becomes one ANY_STRING that matches everything. if (!wcpattern.empty()) {
if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING); if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING);
if (wcpattern.back() != ANY_STRING) wcpattern.push_back(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);
}
} }
} }