X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Futil.cpp;h=a3848fd38432081e01ee399f1e59131e42af13d7;hb=5f3f7465db4444e49dd4a896f88c090b40d0a303;hp=7e0f6625b6a556a773829438405770b9dc6ce847;hpb=0c15e9be384df1db22a714c3ec77e9902df0492f;p=novacoin.git diff --git a/src/util.cpp b/src/util.cpp index 7e0f662..a3848fd 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -31,6 +31,7 @@ namespace boost { #include #include #include +#include #ifdef WIN32 #ifdef _MSC_VER @@ -127,6 +128,13 @@ public: ppmutexOpenSSL[i] = new CCriticalSection(); CRYPTO_set_locking_callback(locking_callback); + // OpenSSL can optionally load a config file which lists optional loadable modules and engines. + // We don't use them so we don't require the config. However some of our libs may call functions + // which attempt to load the config file, possibly resulting in an exit() or crash if it is missing + // or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be + // that the config appears to have been loaded and there are no modules/engines available. + OPENSSL_no_config(); + #ifdef WIN32 // Seed random number generator with screen scrape and other hardware sources RAND_screen(); @@ -293,7 +301,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) buffer += vstrprintf(pszFormat, arg_ptr); va_end(arg_ptr); - int line_start = 0, line_end; + size_t line_start = 0, line_end; while((line_end = buffer.find('\n', line_start)) != -1) { OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str()); @@ -331,7 +339,7 @@ string vstrprintf(const char *format, va_list ap) if (p != buffer) delete[] p; limit *= 2; - p = new char[limit]; + p = new(nothrow) char[limit]; if (p == NULL) throw std::bad_alloc(); } @@ -400,16 +408,16 @@ string FormatMoney(int64_t n, bool fPlus) string str = strprintf("%" PRId64 ".%06" PRId64, quotient, remainder); // Right-trim excess zeros before the decimal point: - int nTrim = 0; - for (int i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i) + size_t nTrim = 0; + for (size_t i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i) ++nTrim; if (nTrim) str.erase(str.size()-nTrim, nTrim); if (n < 0) - str.insert((unsigned int)0, 1, '-'); + str.insert(0u, 1, '-'); else if (fPlus && n > 0) - str.insert((unsigned int)0, 1, '+'); + str.insert(0u, 1, '+'); return str; } @@ -588,6 +596,20 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault) return nDefault; } +int32_t GetArgInt(const std::string& strArg, int32_t nDefault) +{ + if (mapArgs.count(strArg)) + return strtol(mapArgs[strArg]); + return nDefault; +} + +uint32_t GetArgUInt(const std::string& strArg, uint32_t nDefault) +{ + if (mapArgs.count(strArg)) + return strtoul(mapArgs[strArg]); + return nDefault; +} + bool GetBoolArg(const std::string& strArg, bool fDefault) { if (mapArgs.count(strArg)) @@ -1166,13 +1188,11 @@ void createConf() pConf << "rpcuser=user\nrpcpassword=" + randomStrGen(15) + "\nrpcport=8344" - + "\nport=7777" + "\n#(0=off, 1=on) daemon - run in the background as a daemon and accept commands" + "\ndaemon=0" + "\n#(0=off, 1=on) server - accept command line and JSON-RPC commands" + "\nserver=0" - + "\nrpcallowip=127.0.0.1" - + "\ntestnet=0"; + + "\nrpcallowip=127.0.0.1"; pConf.close(); } @@ -1272,7 +1292,7 @@ void ShrinkDebugFile() // Restart the file with some of the end char pch[200000]; fseek(file, -((long long)sizeof(pch)), SEEK_END); - int nBytes = fread(pch, 1, sizeof(pch), file); + size_t nBytes = fread(pch, 1, sizeof(pch), file); fclose(file); file = fopen(pathLog.string().c_str(), "w"); @@ -1312,15 +1332,14 @@ extern int64_t nNtpOffset; static int64_t nNodesOffset = INT64_MAX; // Select time offset: -// -// * If NTP and system clock are in agreement within 40 minutes, then use NTP. -// * If not, then choose between median peer time and system clock using the same condition. int64_t GetTimeOffset() { + // If NTP and system clock are in agreement within 40 minutes, then use NTP. if (abs64(nNtpOffset) < 40 * 60) return nNtpOffset; - if (abs64(nNodesOffset) < 40 * 60) + // If not, then choose between median peer time and system clock. + if (abs64(nNodesOffset) < 70 * 60) return nNodesOffset; return 0; @@ -1481,4 +1500,4 @@ std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) ss.imbue(loc); ss << boost::posix_time::from_time_t(nTime); return ss.str(); -} \ No newline at end of file +}