QWindowsLocalCodec::convertToUnicode(): Fix remaining char conversion

Prevent passing a zero argument to the cbMultiByte parameter of
MultiByteToWideChar. According to the documentation this will always
fail.

This is triggered when calling convertToUnicode with a state having
remainingChars of one and a length of one. The remaining chars will be
completed and the length will be reduced to zero before the actual
convert.

Adding an early return after the completion to prevent calling
MultiByteToWideChar with the invalid zero argument.

Fixes: QTCREATORBUG-21622
Change-Id: Ic6a433dd929e97b1681583cb1b9a347afaa9a09f
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
David Schulz 2018-12-12 08:00:55 +01:00
parent eaf4438b35
commit 9ce4260d23
1 changed files with 5 additions and 1 deletions

View File

@ -83,8 +83,12 @@ QString QWindowsLocalCodec::convertToUnicode(const char *chars, int length, Conv
len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
prev, 2, wc.data(), wc.length());
if (len) {
prepend = true;
sp.append(QChar(wc[0]));
if (mblen == 1) {
state->remainingChars = 0;
return sp;
}
prepend = true;
mb++;
mblen--;
wc[0] = 0;