Bug in QxSqlError.h

You find a bug using QxOrm library and you know how to fix it : submit a patch on this forum

Bug in QxSqlError.h

Postby mdw » Thu Mar 09, 2017 9:15 am

I think I have found some bug in the class sql_error.

Beside the destructor which might be removed, since it is already virtual and noexcept in std::exception:
Code: Select all
   virtual ~sql_error() throw() { ; }

The method what is implemented like this:
Code: Select all
   virtual const char * what() const throw()
   { return (m_error.isValid() ? qPrintable(m_error.text()) : ""); }

With the qPrintable macro expansion:
Code: Select all
#ifndef qPrintable
#  define qPrintable(string) QString(string).toLocal8Bit().constData()
#endif

This becomes:
Code: Select all
   virtual const char * what() const throw()
   { return (m_error.isValid() ? QString(m_error.text()).toLocal8Bit().constData() : ""); }

This means that a new QString object gets allocated and toLocal8Bit() causes the creation of a new QByteArray. But now we return its constData() which may be used later when the byte array has already been deallocated.
According to me we would need to introduce a QByteArray buffer (e.g. m_errorMessage) as the exception member, which lives as long as the exception and remodel what() like this:
Code: Select all
   virtual const char * what() const throw()
   { return (m_error.isValid() ? m_errorMessage.constData() : ""); }
mdw
 
Posts: 34
Joined: Mon Feb 15, 2016 2:45 pm

Re: Bug in QxSqlError.h

Postby qxorm » Thu Mar 09, 2017 12:33 pm

Hello,

Yes you are right : there is a bug in QxSqlError.h file.
I thought I already fixed all qPrintable() call in a previous version of QxOrm library, but I forgot this one : thank you for that :)
I will fix this qPrintable() call for the next release.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Bug in QxSqlError.h

Postby mdw » Thu Mar 09, 2017 1:23 pm

Could you give me your patch of the expected change, so I could apply it already on top of the current release.
Thanks in advance!
mdw
 
Posts: 34
Joined: Mon Feb 15, 2016 2:45 pm

Re: Bug in QxSqlError.h

Postby qxorm » Fri Mar 10, 2017 12:19 pm

I attach the new QxSqlError.h file to this topic so you can apply the patch.

If you want to work with latest BETA version of QxOrm library which include your qPrintable() fix in QxSqlError.h file, here is a link : https://www.qxorm.com/version/QxOrm_1.4.4_BETA_21.zip
FYI, here is the current changes log of this BETA version :
Thx to Jimmy Taker for several improvments and new features in QxModelView module !

- QxModelView module : all models based on qx::IxModel class can now be sorted (on all columns), please note that you can also use QSortFilterProxyModel Qt class to sort your model
- QxModelView module - qx::QxModel<T> : fix setData() with e_auto_update_on_field_change option when an error occurred saving data in database, now previous value is restored if an error occurred
- QxModelView module - qx::IxModel : fix setHeaderData() using it with default role (Qt::EditRole) changes the header in a header view (role Qt::DisplayRole)
- QxModelView module - qx::IxModel : if a description is registered in QxOrm context, then it is displayed in header for each property
- QxModelView module : new feature available to add automatically an empty row at the end of the table to insert quickly new items (setShowEmptyLine() method)
- QxModelView module : possibility to define an intermediate base class between qx::IxModel and qx::QxModel<T> to provide your own model features, for example imagine you develop a drag&drop feature in a class named IxModelDragDrop, you can now create a QxOrm model like this (see the second template parameter) : qx::IxModel * pModel = new qx::QxModel<MyPersistantClass, IxModelDragDrop>();
- QxOrm.pro : fix DESTDIR parameter on Windows
- QxOrm.pri and QxOrm.cmake : add a section to enable QT_USE_QSTRINGBUILDER to optimize QString operations
- QxOrm library is now tested with MSVC 2015 compiler (support all MSVC versions from 2008)
- Fix a bug in QxSqlError.h file with a qPrintable() call on a temporary object


Please let me know if you have any problem with this patch.
Attachments
QxSqlError.zip
Patch on QxSqlError.h file
(1.21 KiB) Downloaded 4460 times
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Bug in QxSqlError.h

Postby mdw » Fri Mar 24, 2017 1:29 pm

Thanks, I think it's okay.
mdw
 
Posts: 34
Joined: Mon Feb 15, 2016 2:45 pm


Return to QxOrm - Submit a patch

Who is online

Users browsing this forum: No registered users and 2 guests