Fixed issue that could cause core_filename_ends_with() to return true when extension.size() > filename.size()

This commit is contained in:
Nathan Woods 2016-07-11 18:05:23 -04:00
parent 32230ae648
commit 210d5cb451

View File

@ -1298,15 +1298,16 @@ bool core_filename_ends_with(const std::string &filename, const std::string &ext
{
auto namelen = filename.length();
auto extlen = extension.length();
bool matches = true;
// first if the extension is bigger than the name, we definitely don't match
bool matches = namelen >= extlen;
// work backwards checking for a match
while (extlen > 0 && namelen > 0)
while (matches && extlen > 0 && namelen > 0)
{
if (tolower((UINT8)filename[--namelen]) != tolower((UINT8)extension[--extlen]))
{
matches = false;
break;
}
}
return matches;
}