From: Kimmo Varis Date: Mon, 13 Sep 2010 15:00:27 +0000 (+0000) Subject: PATCH: #3056974 FileFilterMgr accepts long filepath X-Git-Tag: 2.16.4+-jp-10~1363^2~43 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0dc462ad907a514f5db5d6573531a8eb757f345b;p=winmerge-jp%2Fwinmerge-jp.git PATCH: #3056974 FileFilterMgr accepts long filepath Fixes bug #3050199 Submitted by Matthias Mayer Updates after review. --- diff --git a/Src/FileFilterMgr.cpp b/Src/FileFilterMgr.cpp index 413a93d28..78e728c81 100644 --- a/Src/FileFilterMgr.cpp +++ b/Src/FileFilterMgr.cpp @@ -158,22 +158,12 @@ static void AddFilterPattern(vector *filterList, String & st const char * errormsg = NULL; int erroroffset = 0; - char regexString[200] = {0}; - int regexLen = 0; + + char *regexString = UCS2UTF8_ConvertToUtf8(str.c_str()); int pcre_opts = 0; -#ifdef UNICODE - // For unicode builds, use UTF-8. - // Convert pattern to UTF-8 and set option for PCRE to specify UTF-8. - regexLen = TransformUcs2ToUtf8(str.c_str(), str.length(), - regexString, (int)sizeof(regexString)); - pcre_opts |= PCRE_UTF8; -#else - strcpy(regexString, str.c_str()); - regexLen = strlen(regexString); -#endif + pcre_opts |= PCRE_CASELESS; - pcre *regexp = pcre_compile(regexString, pcre_opts, &errormsg, &erroroffset, NULL); if (regexp) @@ -189,6 +179,7 @@ static void AddFilterPattern(vector *filterList, String & st filterList->push_back(elem); } + UCS2UTF8_Dealloc(regexString); } /** @@ -298,22 +289,9 @@ FileFilter * FileFilterMgr::GetFilterByPath(LPCTSTR szFilterPath) */ BOOL TestAgainstRegList(const vector *filterList, LPCTSTR szTest) { - int ovector[30]; - const String sTest = szTest; - const int ilen = sTest.length() * sizeof(TCHAR) + 1; - char *compString = new char[ilen]; - size_t stringlen; - -#ifdef UNICODE - stringlen = TransformUcs2ToUtf8(sTest.c_str(), sTest.length(), - compString, ilen); -#else - strncpy(compString, sTest.c_str(), sTest.length()); - stringlen = ilen - 1;//linelen(compString); -#endif - - compString[stringlen] = 0; - + int ovector[30]; + size_t stringlen =_tcslen(szTest); + char *compString = UCS2UTF8_ConvertToUtf8(szTest); int result = 0; vector::const_iterator iter = filterList->begin(); while (iter != filterList->end()) @@ -326,7 +304,7 @@ BOOL TestAgainstRegList(const vector *filterList, LPCTSTR sz break; ++iter; } - delete [] compString; + UCS2UTF8_Dealloc(compString); if (result >= 0) return TRUE; return FALSE; diff --git a/Src/Plugins.cpp b/Src/Plugins.cpp index 3099ff9cb..76efecee2 100644 --- a/Src/Plugins.cpp +++ b/Src/Plugins.cpp @@ -286,17 +286,7 @@ void PluginInfo::LoadFilterString() FileFilterElement element; const char * errormsg = NULL; int erroroffset = 0; - const int ilen = _tcslen(sPiece) * sizeof(TCHAR) + 1; - char *regexString = new char[ilen]; - -#ifdef UNICODE - size_t regexLen = TransformUcs2ToUtf8((LPCTSTR)sPiece, _tcslen(sPiece), - regexString, ilen); -#else - strcpy(regexString, (LPCTSTR)sPiece); - size_t regexLen = ilen; -#endif - regexString[regexLen] = 0; + char *regexString = UCS2UTF8_ConvertToUtf8(sPiece); pcre *regexp = pcre_compile(regexString, 0, &errormsg, &erroroffset, NULL); if (regexp) { @@ -304,7 +294,7 @@ void PluginInfo::LoadFilterString() elem->pRegExp = regexp; m_filters->push_back(elem); } - delete [] regexString; + UCS2UTF8_Dealloc(regexString); }; } diff --git a/Src/editlib/ccrystaltextview.cpp b/Src/editlib/ccrystaltextview.cpp index cf4fae903..5f1c755fe 100644 --- a/Src/editlib/ccrystaltextview.cpp +++ b/Src/editlib/ccrystaltextview.cpp @@ -4514,21 +4514,9 @@ FindStringHelper (LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags, int pos; const char * errormsg = NULL; int erroroffset = 0; - const int ilen = _tcslen(pszFindWhat) * sizeof(TCHAR) + 1; - char *regexString = new char[ilen]; + char *regexString = UCS2UTF8_ConvertToUtf8(pszFindWhat); int pcre_opts = 0; -#ifdef UNICODE - // For unicode builds, use UTF-8. - // Convert pattern to UTF-8 and set option for PCRE to specify UTF-8. - size_t regexLen = TransformUcs2ToUtf8(pszFindWhat, _tcslen(pszFindWhat), - regexString, ilen); - pcre_opts |= PCRE_UTF8; -#else - strcpy(regexString, pszFindWhat); - size_t regexLen = ilen; -#endif - regexString[regexLen] = 0; pcre_opts |= PCRE_BSR_ANYCRLF; if ((dwFlags & FIND_MATCH_CASE) == 0) pcre_opts |= PCRE_CASELESS; @@ -4541,20 +4529,10 @@ FindStringHelper (LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags, errormsg = NULL; pe = pcre_study(regexp, 0, &errormsg); } - delete [] regexString; + UCS2UTF8_Dealloc(regexString); int ovector[30]; - int compStringBufLen = _tcslen(pszFindWhere) * sizeof(TCHAR) + 1; - char *compString = new char[compStringBufLen]; - int stringLen = 0; - -#ifdef UNICODE - stringLen = TransformUcs2ToUtf8(pszFindWhere, _tcslen(pszFindWhere), - compString, compStringBufLen); -#else - strncpy(compString, pszFindWhere, compStringBufLen); - stringLen = compStringBufLen; -#endif - compString[stringLen] = 0; + char *compString = UCS2UTF8_ConvertToUtf8(pszFindWhere); + int stringLen = _tcslen(pszFindWhere); int result = pcre_exec(regexp, pe, compString, stringLen, 0, 0, ovector, 30); @@ -4571,7 +4549,7 @@ FindStringHelper (LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags, else pos = -1; - delete [] compString; + UCS2UTF8_Dealloc(compString); pcre_free(regexp); pcre_free(pe); return pos;