diff options
author | Matt Corallo <git@bluematt.me> | 2016-11-29 16:50:49 -0800 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2016-12-23 21:30:15 -0500 |
commit | 2b5f085ad11b4b354f48d77e66698fa386c8abbd (patch) | |
tree | c4271c5b5007958565d443d76829d8dbf5135981 /src/util.cpp | |
parent | c8042a48f01aaf306e108683e40db4bfaf0bbcaa (diff) |
Fix non-const mapMultiArgs[] access after init.
Swap mapMultiArgs for a const-reference to a _mapMultiArgs which is
only accessed in util.cpp
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/util.cpp b/src/util.cpp index 8b3e5f93f0..6625ac9325 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -103,7 +103,8 @@ const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf"; const char * const BITCOIN_PID_FILENAME = "bitcoind.pid"; map<string, string> mapArgs; -map<string, vector<string> > mapMultiArgs; +static map<string, vector<string> > _mapMultiArgs; +const map<string, vector<string> >& mapMultiArgs = _mapMultiArgs; bool fDebug = false; bool fPrintToConsole = false; bool fPrintToDebugLog = true; @@ -238,9 +239,12 @@ bool LogAcceptCategory(const char* category) static boost::thread_specific_ptr<set<string> > ptrCategory; if (ptrCategory.get() == NULL) { - const vector<string>& categories = mapMultiArgs["-debug"]; - ptrCategory.reset(new set<string>(categories.begin(), categories.end())); - // thread_specific_ptr automatically deletes the set when the thread ends. + if (mapMultiArgs.count("-debug")) { + const vector<string>& categories = mapMultiArgs.at("-debug"); + ptrCategory.reset(new set<string>(categories.begin(), categories.end())); + // thread_specific_ptr automatically deletes the set when the thread ends. + } else + ptrCategory.reset(new set<string>()); } const set<string>& setCategories = *ptrCategory.get(); @@ -343,7 +347,7 @@ static void InterpretNegativeSetting(std::string& strKey, std::string& strValue) void ParseParameters(int argc, const char* const argv[]) { mapArgs.clear(); - mapMultiArgs.clear(); + _mapMultiArgs.clear(); for (int i = 1; i < argc; i++) { @@ -371,7 +375,7 @@ void ParseParameters(int argc, const char* const argv[]) InterpretNegativeSetting(str, strValue); mapArgs[str] = strValue; - mapMultiArgs[str].push_back(strValue); + _mapMultiArgs[str].push_back(strValue); } } @@ -543,7 +547,7 @@ void ReadConfigFile(const std::string& confPath) InterpretNegativeSetting(strKey, strValue); if (mapArgs.count(strKey) == 0) mapArgs[strKey] = strValue; - mapMultiArgs[strKey].push_back(strValue); + _mapMultiArgs[strKey].push_back(strValue); } // If datadir is changed in .conf file: ClearDatadirCache(); |