Skip to content

Commit

Permalink
fix empty match overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Stewart committed Nov 1, 2023
1 parent afd42bb commit 7826864
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/item_fuzzy_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,26 @@ bool ItemFuzzyMatcher::requiresFullRescore() {
}

int ItemFuzzyMatcher::calculateScore(Item *item) {
int total;
switch (Config::instance().lengthPreference) {
case SHORT:
total = -strlen(item->text);
break;
case LONG:
total = strlen(item->text);
break;
case NONE:
total = 0;
break;
if (!*item->text) {
return BAD_HEURISTIC;
}

int total = 0;
for (const std::string &query : m_queries) {
int score = matchStart(item->text, query.c_str());
if (score == BAD_HEURISTIC) {
return BAD_HEURISTIC;
}
total += score;
}
return total;
switch (Config::instance().lengthPreference) {
case SHORT:
return total - strlen(item->text);
case LONG:
return total + strlen(item->text);
case NONE:
return total;
}
}

int ItemFuzzyMatcher::matchStart(const char *tp, const char *qp) {
Expand Down

0 comments on commit 7826864

Please sign in to comment.