diff options
author | Rebecca Worledge <rebecca.worledge@qt.io> | 2021-01-02 21:32:12 -0800 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@qt.io> | 2021-01-03 18:46:49 +0000 |
commit | b18b44600c9eeb1577331dc71119c2942e929419 (patch) | |
tree | fc573f092bdc6a651ab1a91dabfe436a585039a5 /src | |
parent | dcf9d6b64b43a6739779ff91c03726ff21ddb3c9 (diff) |
Check that the m_closedShape has a size > 0 before using the iterator
An iterator on m_closedShape is being created and used without checking
if the iterator actually has a valid value. This was not a problem in
Qt5, but in Qt6 causes a crash. This patch adds a check to the QMap, so
that the iterator is not even created if the QMap has a size of 0
Change-Id: Ie7a3ce2ad162bb787fbbb18674bbf9bd95524453
Reviewed-by: Rebecca Worledge <rebecca.worledge@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/bodymovin/bmfreeformshape.cpp | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/src/bodymovin/bmfreeformshape.cpp b/src/bodymovin/bmfreeformshape.cpp index fd5c46b..07133e0 100644 --- a/src/bodymovin/bmfreeformshape.cpp +++ b/src/bodymovin/bmfreeformshape.cpp @@ -170,62 +170,64 @@ void BMFreeFormShape::buildShape(const QJsonObject &shape) void BMFreeFormShape::buildShape(int frame) { - auto it = m_closedShape.constBegin(); - bool found = false; - - if (frame <= it.key()) - found = true; - else { - while (it != m_closedShape.constEnd()) { - if (it.key() <= frame) { - found = true; - break; + if (m_closedShape.size()) { + auto it = m_closedShape.constBegin(); + bool found = false; + + if (frame <= it.key()) + found = true; + else { + while (it != m_closedShape.constEnd()) { + if (it.key() <= frame) { + found = true; + break; + } + ++it; } - ++it; } - } - bool needToClose = false; - if (found) - needToClose = (*it); + bool needToClose = false; + if (found) + needToClose = (*it); - // If there are less than two vertices, cannot make a bezier curve - if (m_vertexList.count() < 2) - return; + // If there are less than two vertices, cannot make a bezier curve + if (m_vertexList.count() < 2) + return; - QPointF s(m_vertexList.at(0).pos.value()); - QPointF s0(s); + QPointF s(m_vertexList.at(0).pos.value()); + QPointF s0(s); - m_path.moveTo(s); - int i=0; + m_path.moveTo(s); + int i = 0; - while (i < m_vertexList.count() - 1) { - QPointF v = m_vertexList.at(i + 1).pos.value(); - QPointF c1 = m_vertexList.at(i).co.value(); - QPointF c2 = m_vertexList.at(i + 1).ci.value(); - c1 += s; - c2 += v; + while (i < m_vertexList.count() - 1) { + QPointF v = m_vertexList.at(i + 1).pos.value(); + QPointF c1 = m_vertexList.at(i).co.value(); + QPointF c2 = m_vertexList.at(i + 1).ci.value(); + c1 += s; + c2 += v; - m_path.cubicTo(c1, c2, v); + m_path.cubicTo(c1, c2, v); - s = v; - i++; - } + s = v; + i++; + } - if (needToClose) { - QPointF v = s0; - QPointF c1 = m_vertexList.at(i).co.value(); - QPointF c2 = m_vertexList.at(0).ci.value(); - c1 += s; - c2 += v; + if (needToClose) { + QPointF v = s0; + QPointF c1 = m_vertexList.at(i).co.value(); + QPointF c2 = m_vertexList.at(0).ci.value(); + c1 += s; + c2 += v; - m_path.cubicTo(c1, c2, v); - } + m_path.cubicTo(c1, c2, v); + } - m_path.setFillRule(Qt::WindingFill); + m_path.setFillRule(Qt::WindingFill); - if (m_direction) - m_path = m_path.toReversed(); + if (m_direction) + m_path = m_path.toReversed(); + } } void BMFreeFormShape::parseEasedVertices(const QJsonObject &keyframe, int startFrame) |