From 2ce4a9f48705095669cb74c8de9d8a72f9d49b0e Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 19 Jun 2019 16:35:28 +0200 Subject: [PATCH] Fix crash in QPainterPath::reserve() Function did not handle default-constructed (null d_ptr) path correctly. Fixes: QTBUG-76516 Change-Id: I2925d4306f7fce34ece6739b18a8e275e7970837 Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qpainterpath.cpp | 3 ++- tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index cbe34c2857..d20faf89a2 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -675,8 +675,9 @@ void QPainterPath::reserve(int size) { Q_D(QPainterPath); if ((!d && size > 0) || (d && d->elements.capacity() < size)) { + ensureData(); detach(); - d->elements.reserve(size); + d_func()->elements.reserve(size); } } diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index 69c961c1a1..c90348e91a 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -189,6 +189,10 @@ void tst_QPainterPath::reserveAndCapacity() p.reserve(0); QVERIFY(p.capacity() >= 1000); + + QPainterPath p2; + p2.reserve(10); + QVERIFY(p.capacity() >= 10); } Q_DECLARE_METATYPE(QPainterPath)