diff options
| author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2026-03-18 17:50:29 +0200 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2026-03-19 15:04:16 +0000 |
| commit | 5b1e02cde21fef4fb9d8e8130818bb49e422dcfa (patch) | |
| tree | dfa084343d8f103a297a0bc001447e3e6ab66395 | |
| parent | df652277439a30a973438577b1a370f4a7d2f47c (diff) | |
| download | busybox-w32-5b1e02cde21fef4fb9d8e8130818bb49e422dcfa.tar.gz busybox-w32-5b1e02cde21fef4fb9d8e8130818bb49e422dcfa.tar.bz2 busybox-w32-5b1e02cde21fef4fb9d8e8130818bb49e422dcfa.zip | |
win32: UTF8_OUTPUT: don't fail due to nwritten value
The "nwritten" argument and failure conditions were added in commit
208649d7b5, as it crashed on windows XP without it, and specifically
because WriteConsoleW on XP expects this to be a non-NULL argument.
However, writeCon_utf8 should not be called on XP - and indeed it's
not since commit 234a3b97d3, because it produces incorrect output
unless the UTF8 manifest is in effect - which never happens on XP.
So it was called due to a bug, and it's not called on XP anymore.
Nevertheless, it's possible that in the future we will support native
Windows Unicode without the manifest - also on XP, and in such case
writeCon_utf8 might get called on XP as well, so keep this argument.
However the nwritten failure condition doesn't belong here.
It's not needed on XP, and MS docs doesn't say that this value should
tested in addition to the return value in order to determine failure,
and theoretically there could be differences unrelated to failure.
So ignore this value when determining failure. Return value is enough.
| -rw-r--r-- | win32/winansi.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 4fc657c0b..53f55d09a 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
| @@ -1468,6 +1468,8 @@ static int writeCon_utf8(int fd, const char *u8buf, size_t u8siz) | |||
| 1468 | 1468 | ||
| 1469 | HANDLE h = (HANDLE)_get_osfhandle(fd); | 1469 | HANDLE h = (HANDLE)_get_osfhandle(fd); |
| 1470 | int wlen = 0; | 1470 | int wlen = 0; |
| 1471 | |||
| 1472 | // unused. XP requires non-NULL arg, if we ever support Unicode on XP | ||
| 1471 | DWORD nwritten = 0; | 1473 | DWORD nwritten = 0; |
| 1472 | 1474 | ||
| 1473 | if (!wbuf) | 1475 | if (!wbuf) |
| @@ -1523,13 +1525,13 @@ static int writeCon_utf8(int fd, const char *u8buf, size_t u8siz) | |||
| 1523 | 1525 | ||
| 1524 | // flush if we have less than two empty spaces | 1526 | // flush if we have less than two empty spaces |
| 1525 | if (wlen > wbufwsiz - 2) { | 1527 | if (wlen > wbufwsiz - 2) { |
| 1526 | if (!WriteConsoleW(h, wbuf, wlen, &nwritten, 0) || nwritten != wlen) | 1528 | if (!WriteConsoleW(h, wbuf, wlen, &nwritten, 0)) |
| 1527 | return -1; | 1529 | return -1; |
| 1528 | wlen = 0; | 1530 | wlen = 0; |
| 1529 | } | 1531 | } |
| 1530 | } | 1532 | } |
| 1531 | 1533 | ||
| 1532 | if (wlen && (!WriteConsoleW(h, wbuf, wlen, &nwritten, 0) || nwritten != wlen)) | 1534 | if (wlen && (!WriteConsoleW(h, wbuf, wlen, &nwritten, 0))) |
| 1533 | return -1; | 1535 | return -1; |
| 1534 | return 0; | 1536 | return 0; |
| 1535 | } | 1537 | } |
