core/systems/LibrarySys.cpp
changeset 2011 d0be3ddbba1e
parent 1974 1967de77ebac
child 2012 bd0a140e2bff
     1.1 --- a/core/systems/LibrarySys.cpp	Thu Apr 17 06:08:18 2008 +0000
     1.2 +++ b/core/systems/LibrarySys.cpp	Thu Apr 17 09:19:36 2008 +0000
     1.3 @@ -352,21 +352,26 @@
     1.4  
     1.5  const char *LibrarySystem::GetFileExtension(const char *filename)
     1.6  {
     1.7 -	size_t end = strlen(filename) - 1;
     1.8 +	size_t len, end, i;
     1.9 +
    1.10 +	len = strlen(filename);
    1.11  
    1.12 -	for (size_t i = end; i >= 0; i--)
    1.13 +	/* Minimum string length for filename with ext would be 3; example: a.a */
    1.14 +	if (len < 3)
    1.15  	{
    1.16 -		if (i > end)
    1.17 +		return NULL;
    1.18 +	}
    1.19 +
    1.20 +	end = len - 1;
    1.21 +
    1.22 +	for (i = end; i <= end; i--)
    1.23 +	{
    1.24 +		if (filename[i] == '/')
    1.25  		{
    1.26  			break;
    1.27  		}
    1.28  
    1.29 -		if (filename[i] == PLATFORM_SEP_CHAR || filename[i] == PLATFORM_SEP_ALTCHAR)
    1.30 -		{
    1.31 -			break;
    1.32 -		}
    1.33 -
    1.34 -		if (filename[i] == '.' && i != end)
    1.35 +		if (filename[i] == '.' && i != end && i != 0)
    1.36  		{
    1.37  			return &filename[++i];
    1.38  		}