From 4e4690bd6be54ce17ef3ab48818fea614bd076cb Mon Sep 17 00:00:00 2001 From: s1lent Date: Fri, 30 Aug 2019 06:07:00 +0700 Subject: [PATCH] Reworked COM_FileExtension for consider some case. --- rehlds/engine/common.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/rehlds/engine/common.cpp b/rehlds/engine/common.cpp index b5d90ac..3bfc2d9 100644 --- a/rehlds/engine/common.cpp +++ b/rehlds/engine/common.cpp @@ -1355,21 +1355,31 @@ void COM_StripExtension(char *in, char *out) char *COM_FileExtension(char *in) { #ifdef REHLDS_FIXES - char *src = in + Q_strlen(in) - 1; + int len = Q_strlen(in); + if (len <= 0) + return ""; // no extension + + char *src = in + len - 1; // back up until a . or the start - while (src != in && *(src - 1) != '.') + while (src >= in && !PATHSEPARATOR(*src)) { + if (*src == '.') + { + src++; // skip dot + + if (*src != '\0') + { + return src; + } + + break; + } + src--; } - // check to see if the '.' is part of a input buffer - if (src == in || PATHSEPARATOR(*src)) - { - return ""; // no extension - } - - return src; + return ""; // no extension #else // #ifdef REHLDS_FIXES static char exten[MAX_PATH]; char *c, *d = NULL;