FTBFS if "-Werror=format-security" flag is used

Brendan Jones brendan.jones.it at gmail.com
Thu Dec 12 21:14:47 UTC 2013


On 12/11/2013 11:00 PM, Kevin Kofler wrote:
> Brendan Jones wrote:
>> What is the best way to handle this case:
>>
>> qWarning(QObject::tr("Client name '%1' occupied.").arg(name).toUtf8());
>>
>> something like, or can I make it simpler:
>>
>> qWarning("%s",qPrintable(QObject::tr("Client name '%1'
>> occupied.").arg(name).toUtf8()));
>
> Use one of:
> qWarning() << QObject::tr("Client name '%1' occupied.").arg(name);
> or:
> qWarning("%s", QObject::tr("Client name '%1'
> occupied.").arg(name).toLocal8Bit().data());
>
> Note that hardcoding toUtf8() is also a bad idea here, the right encoding to
> use is toLocal8Bit(), or this will print junk in non-UTF-8 locales. (In our
> default UTF-8 locales, it will make no difference.)
>
>          Kevin Kofler
>

Thanks!


More information about the devel mailing list