Rewrote ILibrarySys::GetFileExtension() to fix the following issues:
- Crash when NULL was passed - Crash when blank string '\0' was passed - Incorrect result returned when file name began with a period. These files are now considered to not have any extension. --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402074
This commit is contained in:
parent
84bde330cd
commit
1e1f0de4ec
@ -352,21 +352,26 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...)
|
||||
|
||||
const char *LibrarySystem::GetFileExtension(const char *filename)
|
||||
{
|
||||
size_t end = strlen(filename) - 1;
|
||||
size_t len, end, i;
|
||||
|
||||
for (size_t i = end; i >= 0; i--)
|
||||
len = strlen(filename);
|
||||
|
||||
/* Minimum string length for filename with ext would be 3; example: a.a */
|
||||
if (len < 3)
|
||||
{
|
||||
if (i > end)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
end = len - 1;
|
||||
|
||||
for (i = end; i <= end; i--)
|
||||
{
|
||||
if (filename[i] == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (filename[i] == PLATFORM_SEP_CHAR || filename[i] == PLATFORM_SEP_ALTCHAR)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (filename[i] == '.' && i != end)
|
||||
if (filename[i] == '.' && i != end && i != 0)
|
||||
{
|
||||
return &filename[++i];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user