From e4b05e60158207db5854cda7d6516ef5bca2e6fa Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 7 Nov 2021 15:01:03 -0500 Subject: [PATCH] Screwed up checks. --- src/api/system.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index 8e4b5ac2..28485139 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -672,9 +672,9 @@ static int f_fuzzy_match(lua_State *L) { int score = 0, run = 0, increment = files ? -1 : 1; const char* strTarget = files ? str + strLen - 1 : str; const char* ptnTarget = files ? ptn + ptnLen - 1 : ptn; - while (*strTarget && *ptnTarget) { - while (*strTarget == ' ') { strTarget += increment; } - while (*ptnTarget == ' ') { ptnTarget += increment; } + while (strTarget >= str && ptnTarget >= ptn && *strTarget && *ptnTarget) { + while (strTarget >= str && *strTarget == ' ') { strTarget += increment; } + while (ptnTarget >= ptn && *ptnTarget == ' ') { ptnTarget += increment; } if (tolower(*strTarget) == tolower(*ptnTarget)) { score += run * 10 - (*strTarget != *ptnTarget); run++; @@ -685,7 +685,7 @@ static int f_fuzzy_match(lua_State *L) { } strTarget += increment; } - if (*ptnTarget) { return 0; } + if (ptnTarget >= ptn && *ptnTarget) { return 0; } lua_pushnumber(L, score - (int)strLen * 10); return 1; }