X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Futil.cpp;h=f47d1de92ad8524fd5d43b869127249b95865755;hb=afc2bcf340f842111978138a9e04e0b14e5de9fe;hp=16cf2fa867fabcb8a731820f0fedaf9838749fe2;hpb=56d7e2c8baefaa0229b42cef66c97da22c42dd61;p=novacoin.git diff --git a/src/util.cpp b/src/util.cpp index 16cf2fa..f47d1de 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 +#include // for to_lower() +#include // 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 @@ -181,7 +182,7 @@ void RandAddSeedPerfmon() if (ret == ERROR_SUCCESS) { RAND_add(pdata, nSize, nSize/100.0); - memset(pdata, 0, nSize); + OPENSSL_cleanse(pdata, nSize); printf("RandAddSeed() %lu bytes\n", nSize); } #endif @@ -534,24 +535,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: @@ -1154,7 +1155,7 @@ string randomStrGen(int length) { void createConf() { - srand(time(NULL)); + srand(static_cast(time(NULL))); ofstream pConf; #if BOOST_FILESYSTEM_VERSION >= 3 @@ -1270,7 +1271,7 @@ void ShrinkDebugFile() { // Restart the file with some of the end char pch[200000]; - fseek(file, -sizeof(pch), SEEK_END); + fseek(file, -((long long)sizeof(pch)), SEEK_END); int nBytes = fread(pch, 1, sizeof(pch), file); fclose(file);