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
This commit is contained in:
anders_k 2014-07-17 09:21:07 +00:00
parent efbdf196f2
commit d66c9a492f

View file

@ -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 cbofs += cbio; // We only have 1 byte, need to read more to get a complete WCHAR
continue; continue;
} }
bool incompsurr; char oddbyte = (char)(cb % 2), incompsurr;
cb = 0, cbofs = 0; cbofs = 0;
if (incompsurr = IS_HIGH_SURROGATE(p[cch-1])) if (incompsurr = IS_HIGH_SURROGATE(p[cch-1]))
wcl = p[--cch], cbofs = sizeof(WCHAR); // Store leading surrogate part and complete it later wcl = p[--cch], cbofs = sizeof(WCHAR); // Store leading surrogate part and complete it later
if (oddbyte)
oddbyte = iob[cb-1], ++cbofs;
logappendfinal: logappendfinal:
p[cch] = L'\0'; p[cch] = L'\0';
LogMessage(g_sdata.hwnd, p); 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 (!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; goto logappendfinal;
} }
break; break;