diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2017-02-27 12:13:13 +0100 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2017-03-06 18:32:28 +0000 |
commit | 6797570a59529b90b5a28923825b56703173fa56 (patch) | |
tree | c8fed7fd055446518bf1ceee7bf71a7d577b9cee /src/corelib/thread/qfutureinterface.h | |
parent | a170c974a53bde5c6027d3cb25311b819678c546 (diff) |
Fix UB in QFutureInterface: invalid casts from ResultStoreBase to ResultStore<>
ResultStore never actually exists, only ResutStoreBase does. So casting to
ResultStore<T> and calling its member functions is UB. Put the type dependent
function as template member functions within ResultStoreBase and so we don't
need QtPrivate::ResultStore anymore.
Same goes for the iterator.
Change-Id: I739b9d234ba2238977863df77fde3a4471a9abd2
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/thread/qfutureinterface.h')
-rw-r--r-- | src/corelib/thread/qfutureinterface.h | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index 559d26e231..7b12f51e3e 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -159,7 +159,7 @@ public: ~QFutureInterface() { if (!derefT()) - resultStore().clear(); + resultStoreBase().template clear<T>(); } static QFutureInterface canceledResult() @@ -169,7 +169,7 @@ public: { other.refT(); if (!derefT()) - resultStore().clear(); + resultStoreBase().template clear<T>(); QFutureInterfaceBase::operator=(other); return *this; } @@ -184,11 +184,6 @@ public: inline const T &resultReference(int index) const; inline const T *resultPointer(int index) const; inline QList<T> results(); -private: - QtPrivate::ResultStore<T> &resultStore() - { return static_cast<QtPrivate::ResultStore<T> &>(resultStoreBase()); } - const QtPrivate::ResultStore<T> &resultStore() const - { return static_cast<const QtPrivate::ResultStore<T> &>(resultStoreBase()); } }; template <typename T> @@ -199,15 +194,14 @@ inline void QFutureInterface<T>::reportResult(const T *result, int index) return; } - QtPrivate::ResultStore<T> &store = resultStore(); - + QtPrivate::ResultStoreBase &store = resultStoreBase(); if (store.filterMode()) { const int resultCountBefore = store.count(); - store.addResult(index, result); + store.addResult<T>(index, result); this->reportResultsReady(resultCountBefore, resultCountBefore + store.count()); } else { - const int insertIndex = store.addResult(index, result); + const int insertIndex = store.addResult<T>(index, result); this->reportResultsReady(insertIndex, insertIndex + 1); } } @@ -226,7 +220,7 @@ inline void QFutureInterface<T>::reportResults(const QVector<T> &_results, int b return; } - QtPrivate::ResultStore<T> &store = resultStore(); + auto &store = resultStoreBase(); if (store.filterMode()) { const int resultCountBefore = store.count(); @@ -250,14 +244,14 @@ template <typename T> inline const T &QFutureInterface<T>::resultReference(int index) const { QMutexLocker lock(mutex()); - return resultStore().resultAt(index).value(); + return resultStoreBase().resultAt(index).template value<T>(); } template <typename T> inline const T *QFutureInterface<T>::resultPointer(int index) const { QMutexLocker lock(mutex()); - return resultStore().resultAt(index).pointer(); + return resultStoreBase().resultAt(index).template pointer<T>(); } template <typename T> @@ -272,9 +266,9 @@ inline QList<T> QFutureInterface<T>::results() QList<T> res; QMutexLocker lock(mutex()); - QtPrivate::ResultIterator<T> it = resultStore().begin(); - while (it != resultStore().end()) { - res.append(it.value()); + QtPrivate::ResultIteratorBase it = resultStoreBase().begin(); + while (it != resultStoreBase().end()) { + res.append(it.value<T>()); ++it; } |