diff options
author | Fabian Vogt <fvogt@suse.com> | 2016-05-10 10:25:39 +0200 |
---|---|---|
committer | Fabian Vogt <fabian@ritter-vogt.de> | 2016-05-11 19:02:47 +0200 |
commit | dda0418a917136ed16930a556d158565231867b2 (patch) | |
tree | da7cb63d21a8d471c7456aa7d954fef5a824b118 | |
parent | d3d8614b51ea689cc68b50c4889bceb91473d5e5 (diff) | |
download | libproxy-git-dda0418a917136ed16930a556d158565231867b2.tar.gz |
config_kde: Remove use of C++11
- Use std::map::find instead of map::at (issue #29)
- Add additional safety check
- Return as const ref
-rw-r--r-- | libproxy/modules/config_kde.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/libproxy/modules/config_kde.cpp b/libproxy/modules/config_kde.cpp index 515aaac..2f72e8f 100644 --- a/libproxy/modules/config_kde.cpp +++ b/libproxy/modules/config_kde.cpp @@ -156,22 +156,24 @@ private: } // Neither key nor def must contain ' - string kde_config_val(const string &key, const string &def) throw (runtime_error) { + const string &kde_config_val(const string &key, const string &def) throw (runtime_error) { if (cache_needs_refresh()) cache.clear(); - else - try { - // Already in cache? - return cache.at(key); - } catch(...) {} // Not in cache - - string result = command_output( - command + " --file kioslaverc --group 'Proxy Settings' --key '" + key + "' --default '" + def + "'"); + else { + // Already in cache? + map<string, string>::iterator it = cache.find(key); + if(it != cache.end()) + return it->second; + } - // Add result to cache - cache[key] = result; + // Although all values are specified internally and/or validated, + // checking is better than trusting. + if(key.find('\'') != string::npos || def.find('\'') != string::npos) + return def; - return result; + // Add result to cache and return it + return cache[key] = command_output( + command + " --file kioslaverc --group 'Proxy Settings' --key '" + key + "' --default '" + def + "'"); } // Used for cache invalidation |