Date: Sat, 26 Aug 2023 13:40:27 +0100
On Saturday, August 26, 2023, Marcin Jaczewski wrote:
>
> What "repair job"??? You only break code pass point of no return.
> Standard should NEVER allow code like this.
> Reinterpret casting one pointer type to another and then dereferencing
> it is pure UB.
>
> There is simple solution for all this:
>
> ```
> class ComHandler
> {
> std::variant<IXYZComHander*, IABCComHandler*> _data;
> public:
> //common API here
> }
> ```
>
> And use `ComHandler` everywhere instead of butchering the whole C++
> object model.
>
The aforementioned dynamic_cast is inside the SDK, and it always yields a
nullptr (obviously it was never tested). I needed to give them code that
would work with the SDK binary that they currently have. I couldn't apply
the simple solution you suggested, as I can't give out a new binary for the
SDK. So alternatively I gave them a quick fix that works.
C++ is a real-world language that should accommodate real-world difficult
situations. Marking a function as '__verbose' would be helpful for
situations where we need to improvise.
>
> What "repair job"??? You only break code pass point of no return.
> Standard should NEVER allow code like this.
> Reinterpret casting one pointer type to another and then dereferencing
> it is pure UB.
>
> There is simple solution for all this:
>
> ```
> class ComHandler
> {
> std::variant<IXYZComHander*, IABCComHandler*> _data;
> public:
> //common API here
> }
> ```
>
> And use `ComHandler` everywhere instead of butchering the whole C++
> object model.
>
The aforementioned dynamic_cast is inside the SDK, and it always yields a
nullptr (obviously it was never tested). I needed to give them code that
would work with the SDK binary that they currently have. I couldn't apply
the simple solution you suggested, as I can't give out a new binary for the
SDK. So alternatively I gave them a quick fix that works.
C++ is a real-world language that should accommodate real-world difficult
situations. Marking a function as '__verbose' would be helpful for
situations where we need to improvise.
Received on 2023-08-26 12:40:29