• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision7384 (tree)
Time2019-01-10 23:06:21
Authorzmatsuo

Log Message

98クラッシュ対策、ToTchar()系関数の実体をなくした

Change Summary

Incremental Difference

--- trunk/teraterm/common/codeconv.cpp (revision 7383)
+++ trunk/teraterm/common/codeconv.cpp (revision 7384)
@@ -91,8 +91,11 @@
9191 */
9292 wchar_t *_MultiByteToWideChar(const char *str_ptr, size_t str_len, int code_page, size_t *w_len_)
9393 {
94- const DWORD flags = MB_ERR_INVALID_CHARS;
95- wchar_t *wstr_ptr;
94+ DWORD flags = MB_ERR_INVALID_CHARS;
95+ if (code_page == CP_UTF8) {
96+ // CP_UTF8 When this is set, dwFlags must be zero.
97+ flags = 0;
98+ }
9699 if (w_len_ != NULL) {
97100 *w_len_ = 0;
98101 }
@@ -105,7 +108,7 @@
105108 if (len == 0) {
106109 return NULL;
107110 }
108- wstr_ptr = (wchar_t *)malloc(len*sizeof(wchar_t));
111+ wchar_t *wstr_ptr = (wchar_t *)malloc(len*sizeof(wchar_t));
109112 if (wstr_ptr == NULL) {
110113 return NULL;
111114 }
@@ -122,13 +125,11 @@
122125 return wstr_ptr;
123126 }
124127
125-//#if defined(UNICODE)
126128 const char *ToCharW(const wchar_t *strW)
127129 {
128130 const char *strA = _WideCharToMultiByte(strW, 0, CP_ACP, NULL);
129131 return strA;
130132 }
131-//#endif
132133
133134 const char *ToCharA(const char *strA)
134135 {
@@ -138,40 +139,29 @@
138139 const char *ToCharU8(const char *strU8)
139140 {
140141 const wchar_t *strW = _MultiByteToWideChar(strU8, 0, CP_UTF8, NULL);
142+ if (strW == NULL) {
143+ return NULL;
144+ }
141145 const char *strA = _WideCharToMultiByte(strW, 0, CP_ACP, NULL);
142146 free((void *)strW);
143147 return strA;
144148 }
145149
146-const TCHAR *ToTcharA(const char *strA)
150+const wchar_t *ToWcharA(const char *strA)
147151 {
148-#if defined(UNICODE)
149152 wchar_t *strW = _MultiByteToWideChar(strA, 0, CP_ACP, NULL);
150153 return strW;
151-#else
152- return ToCharA(strA);
153-#endif
154154 }
155155
156-const TCHAR *ToTcharW(const wchar_t *strW)
156+const wchar_t *ToWcharW(const wchar_t *strW)
157157 {
158-#if defined(UNICODE)
159158 return _wcsdup(strW);
160-#else
161- return ToCharW(strW);
162-#endif
163159 }
164160
165-const TCHAR *ToTcharU8(const char *strU8)
161+const wchar_t *ToWcharU8(const char *strU8)
166162 {
167163 const wchar_t *strW = _MultiByteToWideChar(strU8, 0, CP_UTF8, NULL);
168-#if defined(UNICODE)
169164 return strW;
170-#else
171- const char *strA = _WideCharToMultiByte(strW, 0, CP_ACP, NULL);
172- free((void *)strW);
173- return strA;
174-#endif
175165 }
176166
177167 const char *ToU8W(const wchar_t *strW)
--- trunk/teraterm/common/codeconv.h (revision 7383)
+++ trunk/teraterm/common/codeconv.h (revision 7384)
@@ -37,22 +37,27 @@
3737 char *_WideCharToMultiByte(const wchar_t *wstr_ptr, size_t wstr_len, int code_page, size_t *mb_len_);
3838 wchar_t *_MultiByteToWideChar(const char *str_ptr, size_t str_len, int code_page, size_t *w_len_);
3939
40-const TCHAR *ToTcharA(const char *strA);
41-const TCHAR *ToTcharW(const wchar_t *strW);
42-const TCHAR *ToTcharU8(const char *strU8);
4340 const char *ToCharA(const char *strA);
4441 const char *ToCharW(const wchar_t *strW);
4542 const char *ToCharU8(const char *strU8);
4643 const wchar_t *ToWcharA(const char *strA);
44+const wchar_t *ToWcharW(const wchar_t *strW);
45+const wchar_t *ToWcharU8(const char *strU8);
4746 const char *ToU8A(const char *strA);
4847 const char *ToU8W(const wchar_t *strW);
4948
5049 #if defined(_UNICODE)
51-#define ToCharT(s) ToCharW(s)
52-#define ToU8T(s) ToU8W(s)
50+#define ToTcharA(s) ToWcharA(s)
51+#define ToTcharW(s) ToWcharW(s)
52+#define ToTcharU8(s) ToWcharU8(s)
53+#define ToCharT(s) ToCharW(s)
54+#define ToU8T(s) ToU8W(s)
5355 #else
54-#define ToCharT(s) ToCharA(s)
55-#define ToU8T(s) ToU8A(s)
56+#define ToTcharA(s) ToCharA(s)
57+#define ToTcharW(s) ToCharW(s)
58+#define ToTcharU8(s) ToCharU8(s)
59+#define ToCharT(s) ToCharA(s)
60+#define ToU8T(s) ToU8A(s)
5661 #endif
5762
5863 #ifdef __cplusplus
@@ -60,13 +65,7 @@
6065 #endif
6166
6267 #ifdef __cplusplus
63-TCHAR *ToTchar(const char *strA);
64-TCHAR *ToTchar(const wchar_t *strW);
65-#endif
6668
67-
68-#ifdef __cplusplus
69-
7069 #if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER > 1910))
7170 #define MOVE_CONSTRUCTOR_ENABLE
7271 #endif
Show on old repository browser