From 6ab99f519b3dd96d5d51a8259f07398542dc9473 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 13 May 2010 19:36:00 +0200 Subject: Don't return configuration value by reference The lifetime of the default value is often not long enough to survive to the next statement, so returning it by reference is dangereous. At the moment there may not be any place that actually tries to use the returned value as a reference, but it's better not to wait on it to happen. This was already fixed on the client after it lead to strange crashes. Reviewed-by: Jared Adams --- src/common/configuration.cpp | 4 ++-- src/common/configuration.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/common') diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp index 71c1811b..80364b0b 100644 --- a/src/common/configuration.cpp +++ b/src/common/configuration.cpp @@ -68,8 +68,8 @@ void Configuration::deinitialize() { } -const std::string &Configuration::getValue(const std::string &key, - const std::string &deflt) +std::string Configuration::getValue(const std::string &key, + const std::string &deflt) { std::map::iterator iter = options.find(key); if (iter == options.end()) return deflt; diff --git a/src/common/configuration.hpp b/src/common/configuration.hpp index 791d35c4..5e930a99 100644 --- a/src/common/configuration.hpp +++ b/src/common/configuration.hpp @@ -38,7 +38,7 @@ namespace Configuration * @param key option identifier. * @param deflt default value. */ - const std::string &getValue(const std::string &key, const std::string &deflt); + std::string getValue(const std::string &key, const std::string &deflt); /** * Gets an option as a string. -- cgit v1.2.3-70-g09d2