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

Rémi Denis-Courmont remi at remlab.net
Wed Apr 24 12:31:34 CEST 2019


Hi,

I am referring to fixing up pointers to C++ object. I don't know what it means to fix pointers to C structures, such as vlc_object_t, up. In other words, this does not seem to follow the rules about C++ pointer inter-convertibility.

Le 24 avril 2019 10:30:21 GMT+03:00, pierre at videolabs.io a écrit :
>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)
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20190424/298ff081/attachment.html>


More information about the vlc-devel mailing list