aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickevents.cpp
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2017-08-14 06:30:25 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2017-08-17 08:43:37 +0000
commit74ca31771f9f936cf4c4bbe9216183d46fcf3617 (patch)
tree4c2903d35a745fd407966dbb16fc1cd5dbe5ad04 /src/quick/items/qquickevents.cpp
parent851443de15754f0e083364dc6128f4e061f2ad4e (diff)
Remove unnecesary if and dead code
182648 Dereference before null check There may be a null pointer dereference, or else the comparison against null is unnecessary. In QQuickEventPoint::estimatedVelocity(): All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476) Coverity-Id: 182648 Change-Id: Ie8ca1a58b9c11f7c459d719ccd0a3f3fa9eaeea5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/items/qquickevents.cpp')
-rw-r--r--src/quick/items/qquickevents.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 1e0d268f93..af2ba232f4 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -826,26 +826,23 @@ QVector2D QQuickEventPoint::estimatedVelocity() const
prevPoint->pos = QPointF();
g_previousPointData->insert(m_pointId, prevPoint);
}
- if (prevPoint) {
- const ulong timeElapsed = m_timestamp - prevPoint->timestamp;
- if (timeElapsed == 0) // in case we call estimatedVelocity() twice on the same QQuickEventPoint
- return m_velocity;
-
- QVector2D newVelocity;
- if (prevPoint->timestamp != 0)
- newVelocity = QVector2D(m_scenePos - prevPoint->pos)/timeElapsed;
-
- // VERY simple kalman filter: does a weighted average
- // where the older velocities get less and less significant
- static const float KalmanGain = 0.7f;
- QVector2D filteredVelocity = newVelocity * KalmanGain + m_velocity * (1.0f - KalmanGain);
-
- prevPoint->velocity = filteredVelocity;
- prevPoint->pos = m_scenePos;
- prevPoint->timestamp = m_timestamp;
- return filteredVelocity;
- }
- return QVector2D();
+ const ulong timeElapsed = m_timestamp - prevPoint->timestamp;
+ if (timeElapsed == 0) // in case we call estimatedVelocity() twice on the same QQuickEventPoint
+ return m_velocity;
+
+ QVector2D newVelocity;
+ if (prevPoint->timestamp != 0)
+ newVelocity = QVector2D(m_scenePos - prevPoint->pos)/timeElapsed;
+
+ // VERY simple kalman filter: does a weighted average
+ // where the older velocities get less and less significant
+ static const float KalmanGain = 0.7f;
+ QVector2D filteredVelocity = newVelocity * KalmanGain + m_velocity * (1.0f - KalmanGain);
+
+ prevPoint->velocity = filteredVelocity;
+ prevPoint->pos = m_scenePos;
+ prevPoint->timestamp = m_timestamp;
+ return filteredVelocity;
}
/*!