[Development] Possible infinite loop in QString::toLocal8bit?

Frédéric Marchal frederic.marchal at wowtechnology.com
Tue Apr 12 12:09:26 CEST 2016


Hi,

I was looking at how QString::toLocal8bit works and, on Windows, it looks like 
it may enter an infinite loop.

If I got it right, QString::toLocal8Bit_helper calls QTextCodec::fromUnicode 
which, on Windows, calls QWindowsLocalCodec::convertFromUnicode in 
qwindowscodec.cpp.

In that function, if WideCharToMultiByte fails because the input string is not 
a valid unicode string, the function displays a qWarning where it helpfully 
output the offending string using QString::toLocal8bit!

If the string cannot be converted in the first place, it won't be possible to 
convert it a second time to display the warning message. Hence the infinite 
loop.

It looks to me like the string should be displayed using QString::toUtf8.

Am I right? Is it worth opening a QTBUG for this?

Frederic




More information about the Development mailing list