From 51511a9bf9bcf7e0aeadc000b6fdb3956e04e477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 25 Jan 2023 09:01:20 +0100 Subject: [PATCH] Fixed broken parsing of KML tracks with empty coordinates --- src/data/kmlparser.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/data/kmlparser.cpp b/src/data/kmlparser.cpp index c8a40d16..70821315 100644 --- a/src/data/kmlparser.cpp +++ b/src/data/kmlparser.cpp @@ -482,6 +482,7 @@ void KMLParser::track(SegmentData &segment) { const char error[] = "gx:coord/when element count mismatch"; int i = 0; + bool empty = false; while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("when")) { @@ -495,6 +496,8 @@ void KMLParser::track(SegmentData &segment) _reader.raiseError("Invalid coordinates"); return; } + if (segment.at(i).coordinates().isNull()) + empty = true; i++; } else if (_reader.name() == QLatin1String("ExtendedData")) extendedData(segment); @@ -507,10 +510,15 @@ void KMLParser::track(SegmentData &segment) return; } - // empty (invalid) coordinates are allowed per KML specification! - for (int i = 0; i < segment.size(); i++) - if (segment.at(i).coordinates().isNull()) - segment.remove(i); + /* empty (invalid) coordinates are allowed per KML specification, but + invalid in our data representation so get rid of the segment entries */ + if (empty) { + SegmentData filtered; + for (int i = 0; i < segment.size(); i++) + if (!segment.at(i).coordinates().isNull()) + filtered.append(segment.at(i)); + segment = filtered; + } } void KMLParser::multiTrack(TrackData &t)