[mythtv-commits] Ticket #2725: dynamic_cast can return NULL, must test
MythTV
mythtv at cvs.mythtv.org
Sat Nov 25 11:37:12 UTC 2006
#2725: dynamic_cast can return NULL, must test
--------------------+-------------------------------------------------------
Reporter: nigel | Owner: nigel
Type: defect | Status: closed
Priority: minor | Milestone: unknown
Component: mythtv | Version: 0.20
Severity: medium | Resolution: invalid
--------------------+-------------------------------------------------------
Comment (by nigel):
I suspect there is something seriously wrong with the GCC vtable parsing,
but I haven't found it. The following:
{{{
Index: mythmainwindow.cpp
===================================================================
--- mythmainwindow.cpp (revision 11820)
+++ mythmainwindow.cpp (working copy)
@@ -1089,9 +1089,32 @@
{
case QEvent::KeyPress:
{
+ QKeyEvent *ke = dynamic_cast<QKeyEvent*>(e);
+
+ if (!ke)
+ {
+ //puts("Dynamic_cast of a QtEvent failed!!!");
+
+ // In some strange situations, e is already a QKeyEvent
+ ke = new QKeyEvent(QEvent::KeyPress, 0, 0, 0);
+
+ if (strcmp(typeid(*e).name(), typeid(*ke).name()) == 0)
+ {
+ delete ke;
+
+ // Same typeid? Safe to do a plain-old cast:
+ ke = static_cast<QKeyEvent*>(e);
+ }
+ else
+ {
+ delete ke;
+ //puts("Did you use -fno-rtti to build?");
+ return false;
+ }
+ }
+
}}}
works. Some debuging reveals typeid(e).name() == "P9QKeyEvent"
(QKeyEvent*), and typeid(*e).name() == "9QKeyEvent" (QKeyEvent). Freaking
weird.
[[BR]]
A few other random dynamic_cast values that aren't checked:
libmyth/settings.cpp line 611, 671, 718, 765, 796, 1402,
libmythtv/darwinfirewirerecorder.cpp line 17, libmythtv/diseqcsettings.cpp
line 1362-3, 1375-6, 1388-89, 1400, 1411, 1422-23, 1434-35, 1447-48,
1473-74
--
Ticket URL: <http://svn.mythtv.org/trac/ticket/2725#comment:3>
MythTV <http://www.mythtv.org/>
MythTV
More information about the mythtv-commits
mailing list