Fix potential crash in QStyleAnimation::updateCurrentTime()
authorJ-P Nurmi <jpnurmi@digia.com>
Tue, 16 Oct 2012 15:39:52 +0000 (17:39 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 17 Oct 2012 18:47:16 +0000 (20:47 +0200)
A parentless/targetless QStyleAnimation calls updateCurrentTime() from
QAbstractAnimation constructor. Avoid the potential crash even if it's
not a valid use case for QStyleAnimation.

Change-Id: I9cd263d105c8ea4b5cbabac9a7680991745ccd95
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
src/widgets/styles/qstyleanimation.cpp

index 297a929..6173dc9 100644 (file)
@@ -83,15 +83,17 @@ bool QStyleAnimation::isUpdateNeeded() const
 
 void QStyleAnimation::updateCurrentTime(int)
 {
-    if (target()->isWidgetType()) {
-        QWidget *widget = static_cast<QWidget *>(target());
-        if (!widget->isVisible() || widget->window()->isMinimized())
-            stop();
-    }
-
-    if (isUpdateNeeded()) {
-        QEvent event(QEvent::StyleAnimationUpdate);
-        QCoreApplication::sendEvent(target(), &event);
+    if (QObject *tgt = target()) {
+        if (tgt->isWidgetType()) {
+            QWidget *widget = static_cast<QWidget *>(tgt);
+            if (!widget->isVisible() || widget->window()->isMinimized())
+                stop();
+        }
+
+        if (isUpdateNeeded()) {
+            QEvent event(QEvent::StyleAnimationUpdate);
+            QCoreApplication::sendEvent(tgt, &event);
+        }
     }
 }