From add95c55108dcda46286846dae5ad12d6ee9057b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 12 Mar 2016 15:03:16 +0100 Subject: tst_QSqlQuery: fix UBs (invalid downcasts, member calls) The existing code derived a helper class from QSqlResult and overloaded two protected functions as public ones so the test could call them after casting QSqlResults to that helper class. Both the cast (which is a C-style cast, but with combined static_cast and const_cast semanics) and the following member function call are undefined behavior. Fix by making the test class a friend of QSqlResult, and dropping the casts. Change-Id: I09de2e2b46976d01cfce25892aec6ad36881d3eb Reviewed-by: Mark Brand --- src/sql/kernel/qsqlresult.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/sql') diff --git a/src/sql/kernel/qsqlresult.h b/src/sql/kernel/qsqlresult.h index c86a8f858f..eeef68d2b8 100644 --- a/src/sql/kernel/qsqlresult.h +++ b/src/sql/kernel/qsqlresult.h @@ -38,6 +38,9 @@ #include #include +// for testing: +class tst_QSqlQuery; + QT_BEGIN_NAMESPACE @@ -54,6 +57,8 @@ class Q_SQL_EXPORT QSqlResult Q_DECLARE_PRIVATE(QSqlResult) friend class QSqlQuery; friend class QSqlTableModelPrivate; + // for testing: + friend class ::tst_QSqlQuery; public: virtual ~QSqlResult(); -- cgit v1.2.3