[vlc-devel] [PATCH] qt: casting to children type in parent constructor is UB

Pierre Lamot pierre at videolabs.io
Tue Apr 23 09:51:59 CEST 2019


  children object isn't built yet.

  Fixes #22187
---
 modules/gui/qt/adapters/variables.hpp | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/modules/gui/qt/adapters/variables.hpp b/modules/gui/qt/adapters/variables.hpp
index 710880cf23..930a7e2238 100644
--- a/modules/gui/qt/adapters/variables.hpp
+++ b/modules/gui/qt/adapters/variables.hpp
@@ -112,17 +112,13 @@ public:
         , m_object(new VLCObjectHolderImpl<T>(nullptr))
         , m_property(property)
     {
-        resetObject<T>(object);
-        Derived* derived = static_cast<Derived*>(this);
-        connect(derived, &Derived::valueChangedInternal, this, &QVLCVariable<Derived, BaseType>::onValueChangedInternal, Qt::QueuedConnection);
     }
 
     virtual ~QVLCVariable()
     {
         if (m_object->get())
         {
-            Derived* derived = static_cast<Derived*>(this);
-            var_DelCallback(m_object->get(), qtu(m_property), value_modified, derived);
+            var_DelCallback(m_object->get(), qtu(m_property), value_modified, this);
             var_Destroy(m_object->get(), qtu(m_property));
         }
     }
@@ -133,7 +129,7 @@ public:
     {
         Derived* derived = static_cast<Derived*>(this);
         if (m_object->get()) {
-            var_DelCallback( m_object->get(), qtu(m_property), value_modified, derived );
+            var_DelCallback( m_object->get(), qtu(m_property), value_modified, this );
             var_Destroy(m_object->get(), qtu(m_property));
         }
 
@@ -160,7 +156,7 @@ public:
             }
 
             var_Create(m_object->get(), qtu(m_property), VLCVarTypeTraits<BaseType>::var_type);
-            var_AddCallback(m_object->get(), qtu(m_property), value_modified, derived);
+            var_AddCallback(m_object->get(), qtu(m_property), value_modified, this);
         }
     }
 
@@ -221,6 +217,8 @@ public:
     QVLCBool(T* object, QString property, QObject* parent = nullptr)
         : QVLCVariable<QVLCBool, bool>(object, property, parent)
     {
+        resetObject<T>(object);
+        connect(this, &QVLCBool::valueChangedInternal, this, &QVLCBool::onValueChangedInternal, Qt::QueuedConnection);
     }
 
 public slots:
@@ -241,6 +239,8 @@ public:
     QVLCString(T* object, QString property, QObject* parent = nullptr)
         : QVLCVariable<QVLCString, QString>(object, property, parent)
     {
+        resetObject<T>(object);
+        connect(this, &QVLCString::valueChangedInternal, this, &QVLCString::onValueChangedInternal, Qt::QueuedConnection);
     }
 
 public slots:
@@ -261,6 +261,8 @@ public:
     QVLCFloat(T* object, QString property, QObject* parent = nullptr)
         : QVLCVariable<QVLCFloat, float>(object, property, parent)
     {
+        resetObject<T>(object);
+        connect(this, &QVLCFloat::valueChangedInternal, this, &QVLCFloat::onValueChangedInternal, Qt::QueuedConnection);
     }
 
 public slots:
@@ -282,6 +284,8 @@ public:
     QVLCInteger(T* object, QString property, QObject* parent = nullptr)
         : QVLCVariable<QVLCInteger, int64_t>(object, property, parent)
     {
+        resetObject<T>(object);
+        connect(this, &QVLCInteger::valueChangedInternal, this, &QVLCInteger::onValueChangedInternal, Qt::QueuedConnection);
     }
 
 public slots:
-- 
2.17.1



More information about the vlc-devel mailing list