From d66c9a492fc2d2dd5584aa2df1efc57ab8b16c3d Mon Sep 17 00:00:00 2001 From: anders_k Date: Thu, 17 Jul 2014 09:21:07 +0000 Subject: [PATCH] Better handling of incomplete WCHAR reads from stdout git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6525 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Makensisw/makensisw.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index 1de61903..ab66cdf7 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -766,19 +766,21 @@ DWORD WINAPI MakeNSISProc(LPVOID TreadParam) { cbofs += cbio; // We only have 1 byte, need to read more to get a complete WCHAR continue; } - bool incompsurr; - cb = 0, cbofs = 0; + char oddbyte = (char)(cb % 2), incompsurr; + cbofs = 0; if (incompsurr = IS_HIGH_SURROGATE(p[cch-1])) wcl = p[--cch], cbofs = sizeof(WCHAR); // Store leading surrogate part and complete it later + if (oddbyte) + oddbyte = iob[cb-1], ++cbofs; logappendfinal: p[cch] = L'\0'; LogMessage(g_sdata.hwnd, p); - p[0] = wcl; + p[0] = wcl, iob[cbofs - !!oddbyte] = oddbyte, cb = 0; if (!rok) // No more data can be read { - if (incompsurr) // Unable to complete the surrogate pair + if (cbofs) // Unable to complete the surrogate pair or odd byte { - p[0] = 0xfffd, cch = 1, incompsurr = false; + p[0] = 0xfffd, cch = 1, cbofs = 0; goto logappendfinal; } break;