Fossil SCM
Split WriteConsoleW call into multiple chunks, when necessary. See [https://connect.microsoft.com/VisualStudio/feedback/details/635230]
Commit
8031947e594396ad845a325bcc994078178ca39d
Parent
16642f9c183f704…
1 file changed
+10
-7
+10
-7
| --- src/utf8.c | ||
| +++ src/utf8.c | ||
| @@ -188,11 +188,11 @@ | ||
| 188 | 188 | ** to a file, -1 is returned and nothing is written |
| 189 | 189 | ** to the console. |
| 190 | 190 | */ |
| 191 | 191 | int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){ |
| 192 | 192 | #ifdef _WIN32 |
| 193 | - int nChar; | |
| 193 | + int nChar, written = 0; | |
| 194 | 194 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 195 | 195 | DWORD dummy; |
| 196 | 196 | |
| 197 | 197 | static int istty[2] = { -1, -1 }; |
| 198 | 198 | if( istty[toStdErr] == -1 ){ |
| @@ -207,17 +207,20 @@ | ||
| 207 | 207 | zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) ); |
| 208 | 208 | if( zUnicode==0 ){ |
| 209 | 209 | return 0; |
| 210 | 210 | } |
| 211 | 211 | nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar); |
| 212 | - if( nChar==0 ){ | |
| 213 | - free(zUnicode); | |
| 214 | - return 0; | |
| 212 | + /* Split WriteConsoleW call into multiple chunks, if necessary. See: | |
| 213 | + * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */ | |
| 214 | + while( written < nChar ){ | |
| 215 | + int size = nChar-written; | |
| 216 | + if (size > 26000) size = 26000; | |
| 217 | + WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode+written, | |
| 218 | + size, &dummy, 0); | |
| 219 | + written += size; | |
| 215 | 220 | } |
| 216 | - zUnicode[nChar] = '\0'; | |
| 217 | - WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar, | |
| 218 | - &dummy, 0); | |
| 221 | + free(zUnicode); | |
| 219 | 222 | return nChar; |
| 220 | 223 | #else |
| 221 | 224 | return -1; /* No-op on unix */ |
| 222 | 225 | #endif |
| 223 | 226 | } |
| 224 | 227 |
| --- src/utf8.c | |
| +++ src/utf8.c | |
| @@ -188,11 +188,11 @@ | |
| 188 | ** to a file, -1 is returned and nothing is written |
| 189 | ** to the console. |
| 190 | */ |
| 191 | int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){ |
| 192 | #ifdef _WIN32 |
| 193 | int nChar; |
| 194 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 195 | DWORD dummy; |
| 196 | |
| 197 | static int istty[2] = { -1, -1 }; |
| 198 | if( istty[toStdErr] == -1 ){ |
| @@ -207,17 +207,20 @@ | |
| 207 | zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) ); |
| 208 | if( zUnicode==0 ){ |
| 209 | return 0; |
| 210 | } |
| 211 | nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar); |
| 212 | if( nChar==0 ){ |
| 213 | free(zUnicode); |
| 214 | return 0; |
| 215 | } |
| 216 | zUnicode[nChar] = '\0'; |
| 217 | WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar, |
| 218 | &dummy, 0); |
| 219 | return nChar; |
| 220 | #else |
| 221 | return -1; /* No-op on unix */ |
| 222 | #endif |
| 223 | } |
| 224 |
| --- src/utf8.c | |
| +++ src/utf8.c | |
| @@ -188,11 +188,11 @@ | |
| 188 | ** to a file, -1 is returned and nothing is written |
| 189 | ** to the console. |
| 190 | */ |
| 191 | int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){ |
| 192 | #ifdef _WIN32 |
| 193 | int nChar, written = 0; |
| 194 | wchar_t *zUnicode; /* Unicode version of zUtf8 */ |
| 195 | DWORD dummy; |
| 196 | |
| 197 | static int istty[2] = { -1, -1 }; |
| 198 | if( istty[toStdErr] == -1 ){ |
| @@ -207,17 +207,20 @@ | |
| 207 | zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) ); |
| 208 | if( zUnicode==0 ){ |
| 209 | return 0; |
| 210 | } |
| 211 | nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar); |
| 212 | /* Split WriteConsoleW call into multiple chunks, if necessary. See: |
| 213 | * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */ |
| 214 | while( written < nChar ){ |
| 215 | int size = nChar-written; |
| 216 | if (size > 26000) size = 26000; |
| 217 | WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode+written, |
| 218 | size, &dummy, 0); |
| 219 | written += size; |
| 220 | } |
| 221 | free(zUnicode); |
| 222 | return nChar; |
| 223 | #else |
| 224 | return -1; /* No-op on unix */ |
| 225 | #endif |
| 226 | } |
| 227 |