• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revisão28735 (tree)
Hora2020-02-08 08:05:52
Autorcsware

Mensagem de Log

Use exact buffer sizes.

Mudança Sumário

Diff

--- trunk/src/Utils/UnicodeUtils.cpp (revision 28734)
+++ trunk/src/Utils/UnicodeUtils.cpp (revision 28735)
@@ -1,6 +1,7 @@
11 // TortoiseSVN - a Windows shell extension for easy version control
22
33 // Copyright (C) 2003-2006, 2008-2013, 2015 - TortoiseSVN
4+// Copyright (C) 2020 - TortoiseGit
45
56 // This program is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU General Public License
@@ -77,7 +78,7 @@
7778
7879 CStringA CUnicodeUtils::GetUTF8(const CStringW& string)
7980 {
80- int size = string.GetLength()+1;
81+ int size = string.GetLength();
8182 CBuffer<char> buffer (4 * size);
8283
8384 // Note: always use the Windows API function, do NOT try to implement a function that's faster.
@@ -85,12 +86,12 @@
8586 int len = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)string, size, buffer, 4*size, 0, NULL);
8687 if (len == 0)
8788 return CStringA();
88- return CStringA (buffer, len-1);
89+ return CStringA (buffer, len);
8990 }
9091
9192 CString CUnicodeUtils::GetUnicode(const CStringA& string)
9293 {
93- int size = string.GetLength()+1;
94+ int size = string.GetLength();
9495 CBuffer<wchar_t> buffer (2*size);
9596
9697 // Note: always use the Windows API function, do NOT try to implement a function that's faster.
@@ -98,24 +99,24 @@
9899 int len = MultiByteToWideChar(CP_UTF8, 0, (const char*)string, size, buffer, 2*size);
99100 if (len == 0)
100101 return CString();
101- return CString (buffer, len-1);
102+ return CString (buffer, len);
102103 }
103104
104105 CString CUnicodeUtils::UTF8ToUTF16 (const std::string& string)
105106 {
106- int size = (int)string.length()+1;
107+ int size = (int)string.length();
107108 CBuffer<wchar_t> buffer (2*size);
108109
109110 int len = MultiByteToWideChar(CP_UTF8, 0, string.c_str(), size, buffer, 2*size);
110111 if (len==0)
111112 return CString();
112- return CString (buffer, len-1);
113+ return CString (buffer, len);
113114 }
114115 #endif //_MFC_VER
115116
116117 std::string CUnicodeUtils::StdGetUTF8(const std::wstring& wide)
117118 {
118- int size = (int)wide.length()+1;
119+ int size = (int)wide.length();
119120 CBuffer<char> buffer (4 * size);
120121
121122 int len = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), size, buffer, 4*size, 0, NULL);
@@ -126,18 +127,18 @@
126127
127128 std::wstring CUnicodeUtils::StdGetUnicode(const std::string& utf8)
128129 {
129- int size = (int)utf8.length()+1;
130+ int size = (int)utf8.length();
130131 CBuffer<wchar_t> buffer (2*size);
131132
132133 int len = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), size, buffer, 2*size);
133134 if (len==0)
134135 return std::wstring();
135- return std::wstring (buffer, len-1);
136+ return std::wstring (buffer, len);
136137 }
137138
138139 std::string CUnicodeUtils::StdAnsiToUTF8( const std::string& ansi )
139140 {
140- int size = (int)ansi.length()+1;
141+ int size = (int)ansi.length();
141142 CBuffer<wchar_t> buffer (2*size);
142143
143144 int len = MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), size, buffer, 2*size);
@@ -147,7 +148,7 @@
147148 len = WideCharToMultiByte(CP_UTF8, 0, buffer, len, buffer2, 4*size, 0, NULL);
148149 if (len == 0)
149150 return ansi;
150- return std::string (buffer2, len-1);
151+ return std::string (buffer2, len);
151152 }
152153
153154 // load a string resource
Show on old repository browser