[Interest] QStringBuilder buffer overflow with string litteral?

ich alex at golks.de
Mon Jan 25 15:26:49 CET 2021


Am January 25, 2021 12:56:45 PM UTC schrieb "Olivier B." <perso.olivier.barthelemy at gmail.com>:
>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

https://xkcd.com/327/

Greetings;)
Alex
-- 
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210125/229aff0d/attachment.html>


More information about the Interest mailing list