aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/util.cpp b/src/util.cpp
index e58001842e..c72b84bfa4 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -5,10 +5,11 @@
#include "util.h"
#include "sync.h"
-#include "strlcpy.h"
#include "version.h"
#include "ui_interface.h"
#include <boost/algorithm/string/join.hpp>
+#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
+#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
@@ -220,8 +221,14 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (fileout)
{
static bool fStartedNewLine = true;
- static boost::mutex mutexDebugLog;
- boost::mutex::scoped_lock scoped_lock(mutexDebugLog);
+
+ // This routine may be called by global destructors during shutdown.
+ // Since the order of destruction of static/global objects is undefined,
+ // allocate mutexDebugLog on the heap the first time this routine
+ // is called to avoid crashes during shutdown.
+ static boost::mutex* mutexDebugLog = NULL;
+ if (mutexDebugLog == NULL) mutexDebugLog = new boost::mutex();
+ boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
// reopen the log file, if requested
if (fReopenDebugLog) {
@@ -499,24 +506,24 @@ void ParseParameters(int argc, const char* const argv[])
mapMultiArgs.clear();
for (int i = 1; i < argc; i++)
{
- char psz[10000];
- strlcpy(psz, argv[i], sizeof(psz));
- char* pszValue = (char*)"";
- if (strchr(psz, '='))
+ std::string str(argv[i]);
+ std::string strValue;
+ size_t is_index = str.find('=');
+ if (is_index != std::string::npos)
{
- pszValue = strchr(psz, '=');
- *pszValue++ = '\0';
+ strValue = str.substr(is_index+1);
+ str = str.substr(0, is_index);
}
- #ifdef WIN32
- _strlwr(psz);
- if (psz[0] == '/')
- psz[0] = '-';
- #endif
- if (psz[0] != '-')
+#ifdef WIN32
+ boost::to_lower(str);
+ if (boost::algorithm::starts_with(str, "/"))
+ str = "-" + str.substr(1);
+#endif
+ if (str[0] != '-')
break;
- mapArgs[psz] = pszValue;
- mapMultiArgs[psz].push_back(pszValue);
+ mapArgs[str] = strValue;
+ mapMultiArgs[str].push_back(strValue);
}
// New 0.6 features: