Re: [Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread ich
Am January 25, 2021 2:47:28 PM UTC schrieb "Olivier B." : >Oh, you are right, thanks. I thought the + operator was on a QString >and >adding a char would be faster than adding a 1-char string, but it just >changed the char* pointer address instead. > >Le lun. 25 janv. 2021 à 15:32, Giuseppe

Re: [Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread Olivier B.
Oh, you are right, thanks. I thought the + operator was on a QString and adding a char would be faster than adding a 1-char string, but it just changed the char* pointer address instead. Le lun. 25 janv. 2021 à 15:32, Giuseppe D'Angelo via Interest < interest@qt-project.org> a écrit : > Hi, > >

Re: [Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread Robert Hairgrove
+1 ... this has indeed bitten me more times than I like to admit! Bob Hairgrove -- On 25.01.21 15:27, Giuseppe D'Angelo via Interest wrote: Hi, Il 25/01/21 13:56, Olivier B. ha scritto:          fields += (fields.isEmpty() ? "" : ", ") + '"' + field + '"'; QStringBuilder usage is a red

Re: [Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread Giuseppe D'Angelo via Interest
Hi, Il 25/01/21 13:56, Olivier B. ha scritto:         fields += (fields.isEmpty() ? "" : ", ") + '"' + field + '"'; QStringBuilder usage is a red herring, pay close attention at what you're doing in the first +: you're summing a const char * (result of the ternary operator) with a char;

Re: [Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread ich
Am January 25, 2021 12:56:45 PM UTC schrieb "Olivier B." : >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

Re: [Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread Robert Hairgrove
Just an idea, not having to do with QStringBuilder ... why not do something like this? QString fields = columns.join(", "); if (fields.isEmpty()) fields = "*"; // ... AFAIK it is only necessary to enclose field names in quotes if the name is an SQL keyword. If you still need to quote them, I

[Interest] QStringBuilder buffer overflow with string litteral?

2021-01-25 Thread Olivier B.
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&