Re: Patch - wrong casts, no cleanup in destructor
From: Dmitry <wipedout_at_yandex.ru>
Date: Fri, 04 Feb 2011 09:37:25 +0300
Hey.
03.02.2011, 22:18, "Stefan Küng" <tortoisesvn_at_gmail.com>:
LOL, this one is very ironic. Yes, static_cast won't work in this very case, but not because "ppv" is of type "void**". "*ppv" is of type "void*", so any object pointer can be copied there even without an explicit cast.
The real reason why static_cast won't work here is because class CShellExt inside TortoiseOverlays only inherits from IShellIconOverlayIdentifier and so it doesn't implement most of the interfaces listed in the if-else comparison chain. In some branches of the if-else comparison C-style cast will work as reinterpret_cast (as in "shut up, stupid compiler, I demand you extinguish fire with kerosene") and the caller will be given a non-null pointer to an object that doesn't implement the requested interface.
That code is copied from CShellExt in TortoiseShell, where the class is indeed inherited from all those interfaces. static_cast works there - I copied that code into a separate project to test. If static_cast was used initially the compiler would prevent such unfortunate use of copy-paste.
Best wishes.
> Stefan
------------------------------------------------------
To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].
|
This is an archived mail posted to the TortoiseSVN Dev mailing list.
This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.