• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision28507 (tree)
Time2019-02-05 01:46:03
Authorcsware

Log Message

Restext changes
* Use stack instead of heap
* Fix off by one errors in Utils.cpp* Drop _CRT_NON_CONFORMING_SWPRINTFS and replace swprintf with swprintf_s
* Use secure crt methods more often where easily exchangeable
* Reduce scope
* No need to double zero array

Based on TortoiseGit merge rev. 85ade35f71eeebaa70674315a3e3ebdbb4305125.

Change Summary

Incremental Difference

--- trunk/src/ResText/ResModule.cpp (revision 28506)
+++ trunk/src/ResText/ResModule.cpp (revision 28507)
@@ -1,6 +1,6 @@
1-// TortoiseSVN - a Windows shell extension for easy version control
1+// TortoiseSVN - a Windows shell extension for easy version control
22
3-// Copyright (C) 2015-2016 - TortoiseGit
3+// Copyright (C) 2015-2019 - TortoiseGit
44 // Copyright (C) 2003-2008, 2010-2017 - TortoiseSVN
55
66 // This program is free software; you can redistribute it and/or
@@ -34,7 +34,6 @@
3434 #include <Imagehlp.h>
3535 #pragma warning(pop)
3636
37-
3837 #pragma comment(lib, "Imagehlp.lib")
3938
4039 #ifndef RT_RIBBON
@@ -342,14 +341,13 @@
342341 int len = GET_WORD(pp);
343342 pp++;
344343 std::wstring msgid = std::wstring(pp, len);
345- WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2];
346- SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR));
347- wcscpy(pBuf, msgid.c_str());
348- CUtils::StringExtend(pBuf);
344+ wchar_t buf[MAX_STRING_LENGTH * 2] = { 0 };
345+ wcscpy_s(buf, msgid.c_str());
346+ CUtils::StringExtend(buf);
349347
350- if (wcslen(pBuf))
348+ if (buf[0])
351349 {
352- std::wstring str = std::wstring(pBuf);
350+ std::wstring str = std::wstring(buf);
353351 RESOURCEENTRY entry = m_StringEntries[str];
354352 InsertResourceIDs(RT_STRING, 0, entry, ((INT_PTR)lpszType - 1) * 16 + i, L"");
355353 if (wcschr(str.c_str(), '%'))
@@ -356,7 +354,6 @@
356354 entry.flag = L"#, c-format";
357355 m_StringEntries[str] = entry;
358356 }
359- delete [] pBuf;
360357 pp += len;
361358 }
362359 UnlockResource(hglStringTable);
@@ -399,24 +396,22 @@
399396 size_t len = GET_WORD(pp);
400397 pp++;
401398 std::wstring msgid = std::wstring(pp, len);
402- WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2];
403- SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR));
404- wcscpy(pBuf, msgid.c_str());
405- CUtils::StringExtend(pBuf);
406- msgid = std::wstring(pBuf);
399+ wchar_t buf[MAX_STRING_LENGTH * 2] = { 0 };
400+ wcscpy_s(buf, msgid.c_str());
401+ CUtils::StringExtend(buf);
402+ msgid = std::wstring(buf);
407403
408404 RESOURCEENTRY resEntry;
409405 resEntry = m_StringEntries[msgid];
410- wcscpy(pBuf, resEntry.msgstr.empty() ? msgid.c_str() : resEntry.msgstr.c_str());
411- ReplaceWithRegex(pBuf);
412- CUtils::StringCollapse(pBuf);
413- size_t newlen = wcslen(pBuf);
406+ wcscpy_s(buf, resEntry.msgstr.empty() ? msgid.c_str() : resEntry.msgstr.c_str());
407+ ReplaceWithRegex(buf);
408+ CUtils::StringCollapse(buf);
409+ size_t newlen = wcslen(buf);
414410 if (newlen)
415411 nMem += newlen;
416412 else
417413 nMem += len;
418414 pp += len;
419- delete [] pBuf;
420415 }
421416
422417 WORD * newTable = new WORD[nMem + (nMem % 2)];
@@ -428,22 +423,21 @@
428423 int len = GET_WORD(p);
429424 p++;
430425 std::wstring msgid = std::wstring(p, len);
431- WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2];
432- SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR));
433- wcscpy(pBuf, msgid.c_str());
434- CUtils::StringExtend(pBuf);
435- msgid = std::wstring(pBuf);
426+ wchar_t buf[MAX_STRING_LENGTH * 2] = { 0 };
427+ wcscpy_s(buf, msgid.c_str());
428+ CUtils::StringExtend(buf);
429+ msgid = std::wstring(buf);
436430
437431 RESOURCEENTRY resEntry;
438432 resEntry = m_StringEntries[msgid];
439- wcscpy(pBuf, resEntry.msgstr.empty() ? msgid.c_str() : resEntry.msgstr.c_str());
440- ReplaceWithRegex(pBuf);
441- CUtils::StringCollapse(pBuf);
442- size_t newlen = wcslen(pBuf);
433+ wcscpy_s(buf, resEntry.msgstr.empty() ? msgid.c_str() : resEntry.msgstr.c_str());
434+ ReplaceWithRegex(buf);
435+ CUtils::StringCollapse(buf);
436+ size_t newlen = wcslen(buf);
443437 if (newlen)
444438 {
445439 newTable[index++] = (WORD)newlen;
446- wcsncpy((wchar_t *)&newTable[index], pBuf, newlen);
440+ wcsncpy((wchar_t *)&newTable[index], buf, newlen);
447441 index += newlen;
448442 m_bTranslatedStrings++;
449443 }
@@ -457,7 +451,6 @@
457451 m_bDefaultStrings++;
458452 }
459453 p += len;
460- delete [] pBuf;
461454 }
462455
463456 if (!UpdateResource(m_hUpdateRes, RT_STRING, lpszType, (m_wTargetLang ? m_wTargetLang : wLanguage), newTable, (DWORD)(nMem + (nMem % 2))*2))
@@ -701,18 +694,16 @@
701694
702695 if (flags & MF_POPUP)
703696 {
704- TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
705- SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
706- wcscpy(pBuf, str);
707- CUtils::StringExtend(pBuf);
697+ wchar_t buf[MAX_STRING_LENGTH] = { 0 };
698+ wcscpy_s(buf, str);
699+ CUtils::StringExtend(buf);
708700
709- std::wstring wstr = std::wstring(pBuf);
701+ std::wstring wstr = std::wstring(buf);
710702 RESOURCEENTRY entry = m_StringEntries[wstr];
711703 if (id)
712704 InsertResourceIDs(RT_MENU, 0, entry, id, L" - PopupMenu");
713705
714706 m_StringEntries[wstr] = entry;
715- delete [] pBuf;
716707
717708 if ((res = ParseMenuResource(res))==0)
718709 return nullptr;
@@ -719,17 +710,16 @@
719710 }
720711 else if (id != 0)
721712 {
722- TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
723- SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
724- wcscpy(pBuf, str);
725- CUtils::StringExtend(pBuf);
713+ wchar_t buf[MAX_STRING_LENGTH] = { 0 };
714+ wcscpy_s(buf, str);
715+ CUtils::StringExtend(buf);
726716
727- std::wstring wstr = std::wstring(pBuf);
717+ std::wstring wstr = std::wstring(buf);
728718 RESOURCEENTRY entry = m_StringEntries[wstr];
729719 InsertResourceIDs(RT_MENU, 0, entry, id, L" - Menu");
730720
731721 TCHAR szTempBuf[1024] = { 0 };
732- swprintf(szTempBuf, L"#: MenuEntry; ID:%u", id);
722+ swprintf_s(szTempBuf, L"#: MenuEntry; ID:%u", id);
733723 MENUENTRY menu_entry;
734724 menu_entry.wID = id;
735725 menu_entry.reference = szTempBuf;
@@ -737,7 +727,6 @@
737727
738728 m_StringEntries[wstr] = entry;
739729 m_MenuEntries[id] = menu_entry;
740- delete [] pBuf;
741730 }
742731 } while (!(flags & MF_END));
743732 return res;
@@ -840,12 +829,11 @@
840829 // Popup menu - note this can also have a non-zero ID
841830 if (menuId == 0)
842831 menuId = (WORD)-1;
843- TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
844- SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
845- wcscpy(pBuf, str);
846- CUtils::StringExtend(pBuf);
832+ wchar_t buf[MAX_STRING_LENGTH] = { 0 };
833+ wcscpy_s(buf, str);
834+ CUtils::StringExtend(buf);
847835
848- std::wstring wstr = std::wstring(pBuf);
836+ std::wstring wstr = std::wstring(buf);
849837 RESOURCEENTRY entry = m_StringEntries[wstr];
850838 // Popup has a DWORD help entry on a DWORD boundary - skip over it
851839 res += 2;
@@ -852,7 +840,7 @@
852840
853841 InsertResourceIDs(RT_MENU, 0, entry, menuId, L" - PopupMenuEx");
854842 TCHAR szTempBuf[1024] = { 0 };
855- swprintf(szTempBuf, L"#: MenuExPopupEntry; ID:%lu", menuId);
843+ swprintf_s(szTempBuf, L"#: MenuExPopupEntry; ID:%lu", menuId);
856844 MENUENTRY menu_entry;
857845 menu_entry.wID = (WORD)menuId;
858846 menu_entry.reference = szTempBuf;
@@ -859,23 +847,21 @@
859847 menu_entry.msgstr = wstr;
860848 m_StringEntries[wstr] = entry;
861849 m_MenuEntries[(WORD)menuId] = menu_entry;
862- delete [] pBuf;
863850
864851 if ((res = ParseMenuExResource(res)) == 0)
865852 return nullptr;
866853 } else if (menuId != 0)
867854 {
868- TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
869- SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
870- wcscpy(pBuf, str);
871- CUtils::StringExtend(pBuf);
855+ wchar_t buf[MAX_STRING_LENGTH] = { 0 };
856+ wcscpy_s(buf, str);
857+ CUtils::StringExtend(buf);
872858
873- std::wstring wstr = std::wstring(pBuf);
859+ std::wstring wstr = std::wstring(buf);
874860 RESOURCEENTRY entry = m_StringEntries[wstr];
875861 InsertResourceIDs(RT_MENU, 0, entry, menuId, L" - MenuEx");
876862
877863 TCHAR szTempBuf[1024] = { 0 };
878- swprintf(szTempBuf, L"#: MenuExEntry; ID:%lu", menuId);
864+ swprintf_s(szTempBuf, L"#: MenuExEntry; ID:%lu", menuId);
879865 MENUENTRY menu_entry;
880866 menu_entry.wID = (WORD)menuId;
881867 menu_entry.reference = szTempBuf;
@@ -882,7 +868,6 @@
882868 menu_entry.msgstr = wstr;
883869 m_StringEntries[wstr] = entry;
884870 m_MenuEntries[(WORD)menuId] = menu_entry;
885- delete [] pBuf;
886871 }
887872 } while (!(bResInfo & 0x80));
888873 return res;
@@ -1014,10 +999,8 @@
1014999 (wAnsi >= 0x3A && wAnsi <= 0x40))
10151000 continue;
10161001
1017- auto pBuf = std::make_unique<WCHAR[]>(1024);
1018- auto pBuf2 = std::make_unique<WCHAR[]>(1024);
1019- SecureZeroMemory(pBuf.get(), 1024 * sizeof(WCHAR));
1020- SecureZeroMemory(pBuf2.get(), 1024 * sizeof(WCHAR));
1002+ wchar_t buf[1024] = { 0 };
1003+ wchar_t buf2[1024] = { 0 };
10211004
10221005 // include the menu ID in the msgid to make sure that 'duplicate'
10231006 // accelerator keys are listed in the po-file.
@@ -1031,7 +1014,7 @@
10311014 // Since "filter" and "find" are most likely translated to words starting
10321015 // with different letters, we need to have a separate accelerator entry
10331016 // for each of those
1034- swprintf(pBuf.get(), L"ID:%u:", wID);
1017+ swprintf_s(buf, L"ID:%u:", wID);
10351018
10361019 // EXACTLY 5 characters long "ACS+X"
10371020 // V = Virtual key (or blank if not used)
@@ -1041,32 +1024,31 @@
10411024 // X = upper case character
10421025 // e.g. "V CS+Q" == Ctrl + Shift + 'Q'
10431026 if ((fFlags & FVIRTKEY) == FVIRTKEY) // 0x01
1044- wcscat(pBuf.get(), L"V");
1027+ wcscat_s(buf, L"V");
10451028 else
1046- wcscat(pBuf.get(), L" ");
1029+ wcscat_s(buf, L" ");
10471030
10481031 if ((fFlags & FALT) == FALT) // 0x10
1049- wcscat(pBuf.get(), L"A");
1032+ wcscat_s(buf, L"A");
10501033 else
1051- wcscat(pBuf.get(), L" ");
1034+ wcscat_s(buf, L" ");
10521035
10531036 if ((fFlags & FCONTROL) == FCONTROL) // 0x08
1054- wcscat(pBuf.get(), L"C");
1037+ wcscat_s(buf, L"C");
10551038 else
1056- wcscat(pBuf.get(), L" ");
1039+ wcscat_s(buf, L" ");
10571040
10581041 if ((fFlags & FSHIFT) == FSHIFT) // 0x04
1059- wcscat(pBuf.get(), L"S");
1042+ wcscat_s(buf, L"S");
10601043 else
1061- wcscat(pBuf.get(), L" ");
1044+ wcscat_s(buf, L" ");
10621045
1063- swprintf(pBuf2.get(), L"%s+%c", pBuf.get(), wAnsi);
1046+ swprintf_s(buf2, L"%s+%c", buf, wAnsi);
10641047
1065- std::wstring wstr = std::wstring(pBuf2.get());
1048+ std::wstring wstr = std::wstring(buf2);
10661049 RESOURCEENTRY AKey_entry = m_StringEntries[wstr];
10671050
10681051 TCHAR szTempBuf[1024] = { 0 };
1069- SecureZeroMemory(szTempBuf, sizeof (szTempBuf));
10701052 std::wstring wmenu;
10711053 pME_iter = m_MenuEntries.find(wID);
10721054 if (pME_iter != m_MenuEntries.end())
@@ -1073,7 +1055,7 @@
10731055 {
10741056 wmenu = pME_iter->second.msgstr;
10751057 }
1076- swprintf(szTempBuf, L"#. Accelerator Entry for Menu ID:%u; '%s'", wID, wmenu.c_str());
1058+ swprintf_s(szTempBuf, L"#. Accelerator Entry for Menu ID:%u; '%s'", wID, wmenu.c_str());
10771059 AKey_entry.automaticcomments.push_back(std::wstring(szTempBuf));
10781060
10791061 m_StringEntries[wstr] = AKey_entry;
@@ -1116,11 +1098,6 @@
11161098 // and change its flags and virtual-key code
11171099 // as appropriate.
11181100
1119- BYTE xfVirt;
1120- wchar_t xkey;
1121- static const size_t BufferSize = 1024;
1122- auto pBuf = std::make_unique<WCHAR[]>(BufferSize);
1123- auto pBuf2 = std::make_unique<WCHAR[]>(BufferSize);
11241101 for (i = 0; i < cAccelerators; i++)
11251102 {
11261103 if ((lpaccelNew[i].key < 0x30) ||
@@ -1128,36 +1105,38 @@
11281105 (lpaccelNew[i].key >= 0x3A && lpaccelNew[i].key <= 0x40))
11291106 continue;
11301107
1131- SecureZeroMemory(pBuf.get(), 1024 * sizeof(WCHAR));
1132- SecureZeroMemory(pBuf2.get(), 1024 * sizeof(WCHAR));
1108+ BYTE xfVirt;
1109+ wchar_t xkey = { 0 };
1110+ wchar_t buf[1024] = { 0 };
1111+ wchar_t buf2[1024] = { 0 };
11331112
1134- swprintf(pBuf.get(), L"ID:%d:", lpaccelNew[i].cmd);
1113+ swprintf_s(buf, L"ID:%d:", lpaccelNew[i].cmd);
11351114
11361115 // get original key combination
11371116 if ((lpaccelNew[i].fVirt & FVIRTKEY) == FVIRTKEY) // 0x01
1138- wcscat(pBuf.get(), L"V");
1117+ wcscat_s(buf, L"V");
11391118 else
1140- wcscat(pBuf.get(), L" ");
1119+ wcscat_s(buf, L" ");
11411120
11421121 if ((lpaccelNew[i].fVirt & FALT) == FALT) // 0x10
1143- wcscat(pBuf.get(), L"A");
1122+ wcscat_s(buf, L"A");
11441123 else
1145- wcscat(pBuf.get(), L" ");
1124+ wcscat_s(buf, L" ");
11461125
11471126 if ((lpaccelNew[i].fVirt & FCONTROL) == FCONTROL) // 0x08
1148- wcscat(pBuf.get(), L"C");
1127+ wcscat_s(buf, L"C");
11491128 else
1150- wcscat(pBuf.get(), L" ");
1129+ wcscat_s(buf, L" ");
11511130
11521131 if ((lpaccelNew[i].fVirt & FSHIFT) == FSHIFT) // 0x04
1153- wcscat(pBuf.get(), L"S");
1132+ wcscat_s(buf, L"S");
11541133 else
1155- wcscat(pBuf.get(), L" ");
1134+ wcscat_s(buf, L" ");
11561135
1157- swprintf(pBuf2.get(), L"%s+%c", pBuf.get(), lpaccelNew[i].key);
1136+ swprintf_s(buf2, L"%s+%c", buf, lpaccelNew[i].key);
11581137
11591138 // Is it there?
1160- std::map<std::wstring, RESOURCEENTRY>::iterator pAK_iter = m_StringEntries.find(pBuf2.get());
1139+ std::map<std::wstring, RESOURCEENTRY>::iterator pAK_iter = m_StringEntries.find(buf2);
11611140 if (pAK_iter != m_StringEntries.end())
11621141 {
11631142 m_bTranslatedAcceleratorStrings++;
@@ -1185,7 +1164,7 @@
11851164 continue; // not a space - user must have made a mistake when translating
11861165 if (wtemp.compare(4, 1, L"+") == 0)
11871166 {
1188- swscanf(wtemp.substr(5, 1).c_str(), L"%c", &xkey);
1167+ swscanf_s(wtemp.substr(5, 1).c_str(), L"%c", &xkey, 1);
11891168 lpaccelNew[i].fVirt = xfVirt;
11901169 lpaccelNew[i].key = (DWORD)xkey;
11911170 }
@@ -1262,31 +1241,28 @@
12621241
12631242 if (dlg.caption)
12641243 {
1265- TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
1266- SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
1267- wcscpy(pBuf, dlg.caption);
1268- CUtils::StringExtend(pBuf);
1244+ wchar_t buf[MAX_STRING_LENGTH] = { 0 };
1245+ wcscpy_s(buf, dlg.caption);
1246+ CUtils::StringExtend(buf);
12691247
1270- std::wstring wstr = std::wstring(pBuf);
1248+ std::wstring wstr = std::wstring(buf);
12711249 RESOURCEENTRY entry = m_StringEntries[wstr];
12721250 InsertResourceIDs(RT_DIALOG, (INT_PTR)lpszType, entry, (INT_PTR)lpszType, L"");
12731251
12741252 m_StringEntries[wstr] = entry;
1275- delete [] pBuf;
12761253 }
12771254
12781255 while (bNumControls-- != 0)
12791256 {
12801257 TCHAR szTitle[500] = { 0 };
1281- SecureZeroMemory(szTitle, sizeof(szTitle));
12821258 BOOL bCode;
12831259
12841260 lpDlgItem = GetControlInfo((WORD *) lpDlgItem, &dlgItem, dlg.dialogEx, &bCode);
12851261
12861262 if (bCode == FALSE)
1287- wcsncpy(szTitle, dlgItem.windowName, _countof(szTitle) - 1);
1263+ wcsncpy_s(szTitle, dlgItem.windowName, _countof(szTitle) - 1);
12881264
1289- if (szTitle[0] != 0)
1265+ if (szTitle[0])
12901266 {
12911267 CUtils::StringExtend(szTitle);
12921268
@@ -2010,10 +1986,11 @@
20101986
20111987 if (entry.msgstr.size())
20121988 {
2013- auto sbuf = std::make_unique<wchar_t[]>(entry.msgstr.size() + 10);
2014- wcscpy(sbuf.get(), entry.msgstr.c_str());
1989+ size_t buflen = entry.msgstr.size() + 10;
1990+ auto sbuf = std::make_unique<wchar_t[]>(buflen);
1991+ wcscpy_s(sbuf.get(), buflen, entry.msgstr.c_str());
20151992 CUtils::StringCollapse(sbuf.get());
2016- ReplaceWithRegex(sbuf.get());
1993+ ReplaceWithRegex(sbuf.get(), buflen);
20171994 std::wstring sreplace = L"<TEXT>";
20181995 sreplace += sbuf.get();
20191996 sreplace += L"</TEXT>";
@@ -2039,10 +2016,11 @@
20392016
20402017 if (entry.msgstr.size())
20412018 {
2042- auto sbuf = std::make_unique<wchar_t[]>(entry.msgstr.size() + 10);
2043- wcscpy(sbuf.get(), entry.msgstr.c_str());
2019+ size_t buflen = entry.msgstr.size() + 10;
2020+ auto sbuf = std::make_unique<wchar_t[]>(buflen);
2021+ wcscpy_s(sbuf.get(), buflen, entry.msgstr.c_str());
20442022 CUtils::StringCollapse(sbuf.get());
2045- ReplaceWithRegex(sbuf.get());
2023+ ReplaceWithRegex(sbuf.get(), buflen);
20462024 std::wstring sreplace = L"</ELEMENT_NAME><NAME>";
20472025 sreplace += sbuf.get();
20482026 sreplace += L"</NAME>";
@@ -2078,7 +2056,7 @@
20782056 MYERROR;
20792057 }
20802058
2081-std::wstring CResModule::ReplaceWithRegex(WCHAR * pBuf)
2059+std::wstring CResModule::ReplaceWithRegex(WCHAR* pBuf, size_t bufferSize)
20822060 {
20832061 for (const auto& t : m_StringEntries.m_regexes)
20842062 {
@@ -2086,7 +2064,7 @@
20862064 {
20872065 std::wregex e(std::get<0>(t), std::regex_constants::icase);
20882066 auto replaced = std::regex_replace(pBuf, e, std::get<1>(t));
2089- wcscpy(pBuf, replaced.c_str());
2067+ wcscpy_s(pBuf, bufferSize, replaced.c_str());
20902068 }
20912069 catch (std::exception&)
20922070 {
@@ -2162,14 +2140,11 @@
21622140 return TRUE;
21632141 }
21642142
2165-#pragma warning(push)
2166-#pragma warning(disable: 4189)
21672143 BOOL CALLBACK CResModule::EnumResNameWriteCallback(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
21682144 {
21692145 auto lpResModule = reinterpret_cast<CResModule*>(lParam);
21702146 return EnumResourceLanguages(hModule, lpszType, lpszName, (ENUMRESLANGPROC)&lpResModule->EnumResWriteLangCallback, lParam);
21712147 }
2172-#pragma warning(pop)
21732148
21742149 BOOL CALLBACK CResModule::EnumResWriteLangCallback(HMODULE /*hModule*/, LPCTSTR lpszType, LPTSTR lpszName, WORD wLanguage, LONG_PTR lParam)
21752150 {
@@ -2203,43 +2178,41 @@
22032178
22042179 void CResModule::ReplaceStr(LPCWSTR src, WORD * dest, size_t * count, int * translated, int * def)
22052180 {
2206- TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
2207- SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
2208- wcscpy(pBuf, src);
2209- CUtils::StringExtend(pBuf);
2181+ wchar_t buf[MAX_STRING_LENGTH] = { 0 };
2182+ wcscpy_s(buf, src);
2183+ CUtils::StringExtend(buf);
22102184
2211- std::wstring wstr = std::wstring(pBuf);
2212- ReplaceWithRegex(pBuf);
2185+ std::wstring wstr = std::wstring(buf);
2186+ ReplaceWithRegex(buf);
22132187 RESOURCEENTRY entry = m_StringEntries[wstr];
22142188 if (!entry.msgstr.empty())
22152189 {
2216- wcscpy(pBuf, entry.msgstr.c_str());
2217- ReplaceWithRegex(pBuf);
2218- CUtils::StringCollapse(pBuf);
2190+ wcscpy_s(buf, entry.msgstr.c_str());
2191+ ReplaceWithRegex(buf);
2192+ CUtils::StringCollapse(buf);
22192193 if (dest)
2220- wcscpy((wchar_t *)&dest[(*count)], pBuf);
2221- (*count) += wcslen(pBuf)+1;
2194+ wcscpy((wchar_t*)&dest[(*count)], buf);
2195+ (*count) += wcslen(buf) + 1;
22222196 (*translated)++;
22232197 }
22242198 else
22252199 {
2226- if (wcscmp(pBuf, wstr.c_str()))
2200+ if (wcscmp(buf, wstr.c_str()))
22272201 {
22282202 if (dest)
2229- wcscpy((wchar_t *)&dest[(*count)], pBuf);
2230- (*count) += wcslen(pBuf) + 1;
2203+ wcscpy((wchar_t*)&dest[(*count)], buf);
2204+ (*count) += wcslen(buf) + 1;
22312205 (*translated)++;
22322206 }
22332207 else
22342208 {
22352209 if (dest)
2236- wcscpy((wchar_t *)&dest[(*count)], src);
2210+ wcscpy((wchar_t*)&dest[(*count)], src);
22372211 (*count) += wcslen(src) + 1;
22382212 if (wcslen(src))
22392213 (*def)++;
22402214 }
22412215 }
2242- delete [] pBuf;
22432216 }
22442217
22452218 static bool StartsWith(const std::string& heystacl, const char* needle)
--- trunk/src/ResText/ResModule.h (revision 28506)
+++ trunk/src/ResText/ResModule.h (revision 28507)
@@ -1,5 +1,6 @@
1-// TortoiseSVN - a Windows shell extension for easy version control
1+// TortoiseSVN - a Windows shell extension for easy version control
22
3+// Copyright (C) 2019 - TortoiseGit
34 // Copyright (C) 2003-2007, 2011-2012, 2014-2017 - TortoiseSVN
45
56 // This program is free software; you can redistribute it and/or
@@ -106,7 +107,12 @@
106107 BOOL ReplaceAccelerator(LPCTSTR lpszType, WORD wLanguage);
107108 BOOL ReplaceRibbon(LPCTSTR lpszType, WORD wLanguage);
108109
109- std::wstring ReplaceWithRegex(WCHAR * pBuf);
110+ template <size_t _Size>
111+ inline std::wstring ReplaceWithRegex(WCHAR (&pBuf)[_Size])
112+ {
113+ return ReplaceWithRegex(pBuf, _Size);
114+ }
115+ std::wstring ReplaceWithRegex(WCHAR* pBuf, size_t bufferSize);
110116 std::wstring ReplaceWithRegex(std::wstring& s);
111117
112118 const WORD* ParseMenuResource(const WORD * res);
--- trunk/src/ResText/Utils.cpp (revision 28506)
+++ trunk/src/ResText/Utils.cpp (revision 28507)
@@ -1,5 +1,6 @@
1-// TortoiseSVN - a Windows shell extension for easy version control
1+// TortoiseSVN - a Windows shell extension for easy version control
22
3+// Copyright (C) 2019 - TortoiseGit
34 // Copyright (C) 2003-2006, 2012-2014 - TortoiseSVN
45
56 // This program is free software; you can redistribute it and/or
@@ -35,7 +36,7 @@
3536 cPos = wcschr(cPos, '\\');
3637 if (cPos)
3738 {
38- memmove(cPos+1, cPos, wcslen(cPos)*sizeof(TCHAR));
39+ memmove(cPos + 1, cPos, (wcslen(cPos) + 1) * sizeof(TCHAR));
3940 *cPos = '\\';
4041 *(cPos+1) = '\\';
4142 cPos++;
@@ -48,7 +49,7 @@
4849 cPos = wcschr(cPos, '\n');
4950 if (cPos)
5051 {
51- memmove(cPos+1, cPos, wcslen(cPos)*sizeof(TCHAR));
52+ memmove(cPos + 1, cPos, (wcslen(cPos) + 1) * sizeof(TCHAR));
5253 *cPos = '\\';
5354 *(cPos+1) = 'n';
5455 }
@@ -59,7 +60,7 @@
5960 cPos = wcschr(cPos, '\r');
6061 if (cPos)
6162 {
62- memmove(cPos+1, cPos, wcslen(cPos)*sizeof(TCHAR));
63+ memmove(cPos + 1, cPos, (wcslen(cPos) + 1) * sizeof(TCHAR));
6364 *cPos = '\\';
6465 *(cPos+1) = 'r';
6566 }
@@ -70,7 +71,7 @@
7071 cPos = wcschr(cPos, '\t');
7172 if (cPos)
7273 {
73- memmove(cPos+1, cPos, wcslen(cPos)*sizeof(TCHAR));
74+ memmove(cPos + 1, cPos, (wcslen(cPos) + 1) * sizeof(TCHAR));
7475 *cPos = '\\';
7576 *(cPos+1) = 't';
7677 }
@@ -81,7 +82,7 @@
8182 cPos = wcschr(cPos, '"');
8283 if (cPos)
8384 {
84- memmove(cPos+1, cPos, wcslen(cPos)*sizeof(TCHAR));
85+ memmove(cPos + 1, cPos, (wcslen(cPos) + 1) * sizeof(TCHAR));
8586 *cPos = '\\';
8687 *(cPos+1) = '"';
8788 cPos++;
Show on old repository browser