[Interest] QStringBuilder buffer overflow with string litteral?
Olivier B.
perso.olivier.barthelemy at gmail.com
Mon Jan 25 13:56:45 CET 2021
Compiling with QT 5.11.1 & QT_USE_QSTRINGBUILDER, i get an error with the
following code block:
QString generateQuery(const QString& tableName, const QStringList&
columns, int count)
{
QString fields = "*";
if (!columns.isEmpty())
{
fields.clear();
for (const QString& field : columns)
{
fields += (fields.isEmpty() ? "" : ", ") + '"' + field + '"';
}
}
...
I just want to build a comma separated list of the items in 'columns',
surrounded by quotes.
But instead of giving "A", "B", "C", this gives UNIQUE (%1)"A"UNIQUE
(%1)"B"UNIQUE (%1)"C"
That UNIQUE (%1) is only found in another cpp file of the same DLL project,
in strings ", UNIQUE (%1)" passed to QString constructors. So not only is
it using the wrong string litteral, it does not read it from the string
start.
Passing one/both of the operands of the ternary operator as QStrings makes
the problem disappear.
Are there things i should be aware of when using QStringBuilder, such as
'do not put expressions on operators, because of macros that will evaluate
them multiple times', or something like that?
String pooling (/GF of visual studio) is not used, if that matters
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210125/6a206097/attachment.html>
More information about the Interest
mailing list