From 8dd8520ddcbe13efbe6c8fa48b7f29c654c1c1e1 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Wed, 30 Jul 2014 21:44:21 +0200 Subject: [PATCH] Rewrite COM_FileExtention() COM_FileExtension() was parsing strings from beginning to end, bailing out as soon as '.' was found and treating everything thereafter as the file extension. That behavior caused problem with relatives pathes like models/monsters/tank/../ctank/skin.pcx. The new implementation uses strrchr() to determine the last '.'. --- src/savegame/tables/gamefunc_decs.h | 2 +- src/shared/shared.c | 24 +++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/savegame/tables/gamefunc_decs.h b/src/savegame/tables/gamefunc_decs.h index 85fb684..5065b72 100644 --- a/src/savegame/tables/gamefunc_decs.h +++ b/src/savegame/tables/gamefunc_decs.h @@ -51,7 +51,7 @@ extern short BigShort ( short l ) ; extern void COM_DefaultExtension ( char * path , const char * extension ) ; extern void COM_FilePath ( const char * in , char * out ) ; extern void COM_FileBase ( char * in , char * out ) ; -extern char * COM_FileExtension ( char * in ) ; +extern const char * COM_FileExtension ( const char * in ) ; extern void COM_StripExtension ( char * in , char * out ) ; extern char * COM_SkipPath ( char * pathname ) ; extern int Q_log2 ( int val ) ; diff --git a/src/shared/shared.c b/src/shared/shared.c index f2d82c0..56d605a 100644 --- a/src/shared/shared.c +++ b/src/shared/shared.c @@ -650,31 +650,17 @@ COM_StripExtension(char *in, char *out) *out = 0; } -char * -COM_FileExtension(char *in) +const char * +COM_FileExtension(const char *in) { - static char exten[8]; - int i; + const char *ext = strrchr(in, '.'); - while (*in && *in != '.') - { - in++; - } - - if (!*in) + if (!ext || ext == in) { return ""; } - in++; - - for (i = 0; i < 7 && *in; i++, in++) - { - exten[i] = *in; - } - - exten[i] = 0; - return exten; + return ext + 1; } void