Fixed MakeNSISW stdout log reader when the buffer is almost full

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6523 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-07-16 20:22:44 +00:00
parent f0e367d00d
commit 481d383c76

View file

@ -753,39 +753,33 @@ DWORD WINAPI MakeNSISProc(LPVOID TreadParam) {
} }
CloseHandle(newstdout); // close this handle (duplicated in subprocess) now so we get ERROR_BROKEN_PIPE CloseHandle(newstdout); // close this handle (duplicated in subprocess) now so we get ERROR_BROKEN_PIPE
char iob[1024 & ~1]; char iob[(1024 & ~1) + sizeof(WCHAR)];
WCHAR *p = (WCHAR*) iob, wcl = 0, wct = 0; WCHAR *p = (WCHAR*) iob, wcl = 0;
DWORD cb = 0, cbofs = 0, cch, cbio; DWORD cbiob = sizeof(iob) - sizeof(WCHAR), cb = 0, cbofs = 0, cch, cbio;
for(;;) for(;;)
{ {
BOOL rok = ReadFile(read_stdout, iob+cbofs, sizeof(iob)-cbofs, &cbio, NULL); BOOL rok = ReadFile(read_stdout, iob+cbofs, cbiob-cbofs, &cbio, NULL);
cb += cbio; cb += cbio, cch = cb / sizeof(WCHAR);
logappend:
cch = cb / sizeof(WCHAR);
if (!cch) if (!cch)
{ {
if (!rok) break; if (!rok) break; // TODO: if cb is non-zero we should report a incomplete read error?
cbofs += cbio; cbofs += cbio; // We only have 1 byte, need to read more to get a complete WCHAR
continue; continue;
} }
bool fullbuf = sizeof(iob) == cb, incompsurr = false; bool incompsurr;
cbofs = 0, cb = 0, --cch; cb = 0, cbofs = 0;
if (fullbuf || (incompsurr = IS_HIGH_SURROGATE(p[cch]))) 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); logappendfinal:
if (cch && IS_HIGH_SURROGATE(p[cch-1]) && !incompsurr)
wct = wcl, wcl = p[cch-1], cbofs += sizeof(WCHAR);
}
p[cch] = L'\0'; p[cch] = L'\0';
LogMessage(g_sdata.hwnd, p); LogMessage(g_sdata.hwnd, p);
p[0] = wcl, p[1] = wct; p[0] = wcl;
if (!rok) if (!rok) // No more data can be read
{ {
if (cbofs) if (incompsurr) // Unable to complete the surrogate pair
{ {
if (incompsurr) p[0] = 0xfffd, cbofs = sizeof(WCHAR); // Unable to complete the surrogate pair p[0] = 0xfffd, cch = 1, incompsurr = false;
cb = cbofs; goto logappendfinal;
goto logappend;
} }
break; break;
} }