diff options
author | Andrey Nazarov <skuller@skuller.net> | 2007-08-22 17:23:57 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2007-08-22 17:23:57 +0000 |
commit | 1bef88894b7d80308460f480fb84958f65922e02 (patch) | |
tree | c7d6cd2b9a0bad7405ca75b79eda9df2d6471bac /source/files.c | |
parent | e6f9f100490b454a271f69f4af58eafbde92a87d (diff) |
FS_ExtCmp now correctly handles complex extensions, e.g. '.dm2.gz'.
Fixed NULL pointer dereference when CL_Disconnect is called before
client finishes initialization.
Diffstat (limited to 'source/files.c')
-rw-r--r-- | source/files.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/source/files.c b/source/files.c index 1f1adea..b2c9a4e 100644 --- a/source/files.c +++ b/source/files.c @@ -1756,35 +1756,47 @@ qboolean FS_WildCmp( const char *filter, const char *string ) { return qfalse; } -qboolean FS_ExtCmp( const char *ext, const char *string ) { +qboolean FS_ExtCmp( const char *ext, const char *name ) { int c1, c2; - const char *s; - + const char *e, *n, *l; + + if( !name[0] || !ext[0] ) { + return qfalse; + } + + for( l = name; l[1]; l++ ) + ; + + for( e = ext; e[1]; e++ ) + ; + rescan: - s = string; + n = l; do { - c1 = *ext++; - c2 = *s++; + c1 = *e--; + c2 = *n--; if( c1 == ';' ) { - if( c2 ) { - goto rescan; - } - return qtrue; + break; // matched } - c1 = Q_tolower( c1 ); - c2 = Q_tolower( c2 ); if( c1 != c2 ) { - while( c1 ) { - c1 = *ext++; - if( c1 == ';' ) { - goto rescan; + c1 = Q_tolower( c1 ); + c2 = Q_tolower( c2 ); + if( c1 != c2 ) { + while( e > ext ) { + c1 = *e--; + if( c1 == ';' ) { + goto rescan; + } } + return qfalse; } + } + if( n < name ) { return qfalse; } - } while( c1 ); + } while( e >= ext ); return qtrue; } @@ -1903,7 +1915,7 @@ char **FS_ListFiles( const char *path, const char *extension, } // check extension - if( extension && !FS_ExtCmp( extension, COM_FileExtension( name ) ) ) { + if( extension && !FS_ExtCmp( extension, name ) ) { continue; } |