]> git.lyx.org Git - features.git/commitdiff
Do not return a reference to a temporary variable
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 1 Mar 2017 16:35:05 +0000 (17:35 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 1 Mar 2017 16:37:41 +0000 (17:37 +0100)
Coverity correctly spotted that the existing code creates a temporary
map and returns a value from it. It is not possible to make the map
const& directly because operator[] may change the map.

Therefore, we use map::find instead.

src/BufferParams.cpp

index 4cbf2279014ae3a00a778d1e625b67b01d811157..f20078bdff3e97cf742aec331ac7b9b4f055c3fb 100644 (file)
@@ -3305,8 +3305,12 @@ bool BufferParams::addCiteEngine(vector<string> const & engine)
 
 string const & BufferParams::defaultBiblioStyle() const
 {
-       map<string, string> bs = documentClass().defaultBiblioStyle();
-       return bs[theCiteEnginesList.getTypeAsString(citeEngineType())];
+       map<string, string> const & bs = documentClass().defaultBiblioStyle();
+       auto cit = bs.find(theCiteEnginesList.getTypeAsString(citeEngineType()));
+       if (cit != bs.end())
+               return cit->second;
+       else
+               return empty_string();
 }