From 8bee4fa072994d11421efde8cf3e852f4887c2a5 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 7 Jun 2019 12:54:34 +0800 Subject: [PATCH] file_io: fix extension compare. --- file_io.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/file_io.cpp b/file_io.cpp index f32b84b..ec9478c 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -1100,6 +1100,7 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons char *fext = strrchr(de->d_name, '.'); while(!found && *ext && fext) { + fext++; char e[4]; memcpy(e, ext, 3); if (e[2] == ' ') @@ -1107,13 +1108,17 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons e[2] = 0; if (e[1] == ' ') e[1] = 0; } + e[3] = 0; found = 1; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 4; i++) { if (e[i] == '*') break; - if (e[i] == '?' && fext[i+1]) continue; - if (tolower(e[i]) != tolower(fext[i + 1])) found = 0; + if (e[i] == '?' && fext[i]) continue; + + if (tolower(e[i]) != tolower(fext[i])) found = 0; + + if (!e[i] || !found) break; } if (found) break;