summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2018-10-24 09:21:15 +0200
committerAlex Blasche <alexander.blasche@qt.io>2018-10-24 08:25:31 +0000
commit6b109d09982e09940dc8e777430a04410d7b6550 (patch)
treef32047f399643ff7a175f818423f93468f2777cf
parentf9a1c4a18a3421617e28d2c26d30b011d22a0229 (diff)
downloadqtlocation-6b109d09982e09940dc8e777430a04410d7b6550.tar.gz
Fix crash when calling QGeoPath::length on empty QGeoPath instance
Fixes: QTBUG-71355 Change-Id: I47b058891a47cd6d020c4e192d40233c57814313 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
-rw-r--r--src/positioning/qgeopath.cpp3
-rw-r--r--tests/auto/qgeopath/tst_qgeopath.cpp1
2 files changed, 4 insertions, 0 deletions
diff --git a/src/positioning/qgeopath.cpp b/src/positioning/qgeopath.cpp
index 94a14ad1..d86f6d0c 100644
--- a/src/positioning/qgeopath.cpp
+++ b/src/positioning/qgeopath.cpp
@@ -464,6 +464,9 @@ void QGeoPathPrivate::setWidth(const qreal &width)
double QGeoPathPrivate::length(int indexFrom, int indexTo) const
{
+ if (path().isEmpty())
+ return 0.0;
+
bool wrap = indexTo == -1;
if (indexTo < 0 || indexTo >= path().size())
indexTo = path().size() - 1;
diff --git a/tests/auto/qgeopath/tst_qgeopath.cpp b/tests/auto/qgeopath/tst_qgeopath.cpp
index 86ff137d..5781e504 100644
--- a/tests/auto/qgeopath/tst_qgeopath.cpp
+++ b/tests/auto/qgeopath/tst_qgeopath.cpp
@@ -70,6 +70,7 @@ void tst_QGeoPath::defaultConstructor()
QGeoPath p;
QVERIFY(!p.path().size());
QCOMPARE(p.width(), qreal(0.0));
+ QCOMPARE(p.length(), double(0.0));
}
void tst_QGeoPath::listConstructor()