From afead4e749794e6d0f6b9cb9bd7897face64104a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 11 May 2017 10:35:45 -0700 Subject: [PATCH] [core] Return {Source,Layer}::getID by value Avoid dangling references in the following sequence: auto& id = layer->getID(); layer->setMaxZoom(2); std::cout << id; The reference would be dangling because mutating the layer allocates a new Immutable impl, and there may be no references to the prior impl, which held the id. --- include/mbgl/style/layer.hpp | 2 +- include/mbgl/style/source.hpp | 2 +- src/mbgl/style/layer.cpp | 2 +- src/mbgl/style/source.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 10176879c..61706d400 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -92,7 +92,7 @@ public: } LayerType getType() const; - const std::string& getID() const; + std::string getID() const; // Visibility VisibilityType getVisibility() const; diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index d19dfd4e3..cec961945 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -56,7 +56,7 @@ public: } SourceType getType() const; - const std::string& getID() const; + std::string getID() const; optional getAttribution() const; // Private implementation diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index fe51dd09c..142fe313c 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -18,7 +18,7 @@ LayerType Layer::getType() const { return baseImpl->type; } -const std::string& Layer::getID() const { +std::string Layer::getID() const { return baseImpl->id; } diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index 4fcebc837..e7701b8be 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -19,7 +19,7 @@ SourceType Source::getType() const { return baseImpl->type; } -const std::string& Source::getID() const { +std::string Source::getID() const { return baseImpl->id; }