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

pierre at videolabs.io pierre at videolabs.io
Wed Apr 24 09:30:21 CEST 2019


On 2019-04-23 17:38, Rémi Denis-Courmont wrote:
> Le tiistaina 23. huhtikuuta 2019, 10.51.59 EEST Pierre Lamot a écrit :
>>   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));
> 
> Uh... Doesn't this incorrectly assume that pointer fixup is 
> unnecessary?

The object can be downcasted to its Derived form as we know its type by 
construction (CRTP)....well except in the Ctor/Dtor of the parent class.
This is the responsibility of the VLCObjectHolderImpl class to return 
the vlc_object_t of the object it owns through the get method.

but maybe I missed something with the recent changes to the objects 
(though it would rather impact VLCObjectHolderImpl implementation)


More information about the vlc-devel mailing list