Mismatch in parsed GeoDataDocument and GeoSceneGeodata in MarbleModelPrivate::assignFillColors(const QString &filePath)
ClosedPublic

Authored by abhgangwar on Apr 11 2017, 7:25 AM.

Details

Summary

In method MarbleModelPrivate::assignFillColors(const QString &filePath) :

If the inner loop, which is iterating over the GeoSceneGeodata set in a layer, finds valid GeoSceneGeodata in the layer, the variable data becomes nonnull. If the data is nonnull, it causes the outer loop to exit even when the source file of GeoSceneData and path of parsed file don't match ( the condition data->sourceFile() == filePath in inner loop ). This results in applying wrong GeoSceneGeodata to a GeoDataDocument.

Diff Detail

Repository
R34 Marble
Lint
Lint Skipped
Unit
Unit Tests Skipped
abhgangwar edited the summary of this revision. (Show Details)Apr 11 2017, 7:27 AM

Good catch!

What happens if found is always false? Perhaps data (i.e. the variable declared outside of the loops) should only be assigned if sourceFile() == filePath. In other words, it looks like the found variable could be replaced by a temporary variable being directly assigned by the dynamic_cast and that variable is assigned to data if the if condition matches. Right?

abhgangwar updated this revision to Diff 13552.Apr 18 2017, 5:57 AM

Yes, that's a better solution. Updated the diff.

nienhueser edited edge metadata.Apr 18 2017, 7:44 PM

Now data is called uninitialized in data->sourceFile(), no? I think shentey meant this instead:

diff --git a/src/lib/marble/MarbleModel.cpp b/src/lib/marble/MarbleModel.cpp
index 967479496..e8d190cf4 100644
--- a/src/lib/marble/MarbleModel.cpp
+++ b/src/lib/marble/MarbleModel.cpp
@@ -759,8 +759,9 @@ void MarbleModelPrivate::assignFillColors(const QString &filePath)
         }
 
         for (auto dataset: layer->datasets()) {
-            data = dynamic_cast<const GeoSceneGeodata *>(dataset);
-            if (data != nullptr && data->sourceFile() == filePath) {
+            auto sceneData = dynamic_cast<const GeoSceneGeodata *>(dataset);
+            if (sceneData != nullptr && sceneData->sourceFile() == filePath) {
+                data = sceneData;
                 break;
             }
         }

Yes, I think shentey meant that. I got it wrong.
Looks good !

shentey added inline comments.Apr 23 2017, 11:09 AM
src/lib/marble/MarbleModel.cpp
762 ↗(On Diff #13552)

This does not work. data is used before it is assigned a non-nullptr. I indeed meant the solution provided by Earthwings.

Updated the patch as earthwings and shentey suggested.

nienhueser accepted this revision.Apr 30 2017, 8:10 AM

Looks good, please push.

This revision is now accepted and ready to land.Apr 30 2017, 8:10 AM
nienhueser added a project: Marble.