diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2018-04-16 22:31:23 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2018-10-25 13:30:30 +0000 |
commit | 65870525c01915fadaa322599b6f9064995d7762 (patch) | |
tree | ee0ba3b5d846a6cdf55e9428f8adb19b7235c561 | |
parent | f3b296ff5c6f0c7478dfd705c69e530d24eece95 (diff) |
Fix UBSAN warning when downcasting partially destroyed object
This patch fixes the runtime warning cought by UBSAN:
src/webchannel/qwebchannel.cpp:84:96: runtime error: downcast of address 0x6030001b1570 which does not point to an object of type 'QWebChannelAbst
Change-Id: I9c78f94bc97961ef69b71ecca8a9301d81feaf3a
Reviewed-by: Kai Dohmen <psykai1993@googlemail.com>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r-- | src/webchannel/qwebchannel.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/webchannel/qwebchannel.cpp b/src/webchannel/qwebchannel.cpp index 0e9a4c5..050d04e 100644 --- a/src/webchannel/qwebchannel.cpp +++ b/src/webchannel/qwebchannel.cpp @@ -46,6 +46,8 @@ #include <QJsonDocument> #include <QJsonObject> +#include <algorithm> + QT_BEGIN_NAMESPACE /*! @@ -81,10 +83,10 @@ QT_BEGIN_NAMESPACE */ void QWebChannelPrivate::_q_transportDestroyed(QObject *object) { - QWebChannelAbstractTransport *transport = static_cast<QWebChannelAbstractTransport*>(object); - const int idx = transports.indexOf(transport); - if (idx != -1) { - transports.remove(idx); + auto it = std::find(transports.begin(), transports.end(), object); + if (it != transports.end()) { + auto *transport = *it; + transports.erase(it); publisher->transportRemoved(transport); } } |