[Interest] Internal Qt bug or incorrect user API call?

T Stutts taycode at gmail.com
Sat Aug 9 01:46:14 CEST 2014

This is a copy of my post at http://qt-project.org/forums/viewthread/46102/
and I am taking the replied suggestion of asking the mailing list. I hope
the copy/pasted markup is okay.

What does this line
 *[qt.gitorious.org <http://qt.gitorious.org>]* line do?
I am referring to the line

   1. new (ptr+(s++)) T(*abuf++);

in this function:

   1. template <class T, int Prealloc>
   2. Q_OUTOFLINE_TEMPLATE void QVarLengthArray
   const T *abuf, int increment)
   3. {
   4.     Q_ASSERT(abuf);
   5.     if (increment <= 0)
   6.         return;
   8.     const int asize = s + increment;
   10.     if (asize >= a)
   11.         realloc(s, qMax(s*2, asize));
   13.     if (QTypeInfo <http://qt-project.org/doc/QTypeInfo.html><T>::
   isComplex) {
   14.         // call constructor for new objects (which can throw)
   15.         while (s < asize)
   16.             new (ptr+(s++)) T(*abuf++);
   17.     } else {
   18.         qMemCopy(&ptr[s], abuf, increment * sizeof(T));
   19.         s = asize;
   20.     }
   21. }

It looks to me like an explicit memory leak (see new()
<http://en.cppreference.com/w/cpp/language/new> *[en.cppreference.com
It expressly allocates dynamic memory and does not store the pointer
anywhere, unless Qt has its own allocation implementation (ie

I am asking because I am seeing random crashes in my ODBC application when
retrieving an output parameter.
Tracing the call, it's coming from an access violation attempting to read
the location of*abuf* in the above *append()* function called from this
line in QODBCResult::exec()

   1. array.append((SQLTCHAR *)first.constData(), first.size());

Normally this pointer seems correct, except when it crashes (debugging in
Visual Studio 2012) with a read access violation because this pointer is
apparently unreadable. Stepping back to *QODBCResult::exec()*, the
variables seem normal and the output parameter seems to have been retrieved

What is causing this? How can I fix it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140808/1417f6cc/attachment.html>

More information about the Interest mailing list