X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fdb.cpp;h=757a18e40ca9ba747218cdc07aa0011531c211ea;hb=e10fa48ea2c24f9647668aafa1f9caa48a51de2f;hp=e0f724c29377e0e1809eaa5b4d5c1baa206af7c8;hpb=77a43545b4491b9703d803765da9059d2bdd5aaa;p=novacoin.git diff --git a/src/db.cpp b/src/db.cpp index e0f724c..757a18e 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -42,11 +42,7 @@ void CDBEnv::EnvShutdown() DbEnv(0).remove(strPath.c_str(), 0); } -CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS) -{ - fDbEnvInit = false; - fMockDb = false; -} +CDBEnv::CDBEnv() : fDetachDB(false), fDbEnvInit(false), fMockDb(false), dbenv(DB_CXX_NO_EXCEPTIONS) { } CDBEnv::~CDBEnv() { @@ -78,7 +74,7 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_) if (GetBoolArg("-privdb", true)) nEnvFlags |= DB_PRIVATE; - int nDbCache = GetArg("-dbcache", 25); + int nDbCache = GetArgInt("-dbcache", 25); dbenv.set_lg_dir(pathLogDir.string().c_str()); dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1); dbenv.set_lg_bsize(1048576); @@ -122,13 +118,13 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_) nBlocks = nMaxLocks / 48768; nDeepReorg = (nBlocks - 1) / 2; - printf("Final lk_max_locks is %lu, sufficient for (worst case) %d block%s in a single transaction (up to a %d-deep reorganization)\n", (unsigned long)nMaxLocks, nBlocks, (nBlocks == 1) ? "" : "s", nDeepReorg); + printf("Final lk_max_locks is %u, sufficient for (worst case) %d block%s in a single transaction (up to a %d-deep reorganization)\n", nMaxLocks, nBlocks, (nBlocks == 1) ? "" : "s", nDeepReorg); if (nDeepReorg < 3) { if (nBlocks < 1) - strMessage = strprintf(_("Warning: DB_CONFIG has set_lk_max_locks %lu, which may be too low for a single block. If this limit is reached, NovaCoin may stop working."), (unsigned long)nMaxLocks); + strMessage = strprintf(_("Warning: DB_CONFIG has set_lk_max_locks %u, which may be too low for a single block. If this limit is reached, NovaCoin may stop working."), nMaxLocks); else - strMessage = strprintf(_("Warning: DB_CONFIG has set_lk_max_locks %lu, which may be too low for a common blockchain reorganization. If this limit is reached, NovaCoin may stop working."), (unsigned long)nMaxLocks); + strMessage = strprintf(_("Warning: DB_CONFIG has set_lk_max_locks %u, which may be too low for a common blockchain reorganization. If this limit is reached, NovaCoin may stop working."), nMaxLocks); strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); @@ -226,7 +222,7 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive, while (!strDump.eof() && keyHex != "DATA=END") { getline(strDump, keyHex); - if (keyHex != "DATA_END") + if (keyHex != "DATA=END") { getline(strDump, valueHex); vResult.push_back(make_pair(ParseHex(keyHex),ParseHex(valueHex))); @@ -254,7 +250,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) : return; fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); - bool fCreate = strchr(pszMode, 'c'); + bool fCreate = strchr(pszMode, 'c') != NULL; unsigned int nFlags = DB_THREAD; if (fCreate) nFlags |= DB_CREATE; @@ -335,7 +331,7 @@ void CDB::Close() if (IsChainFile(strFile) && IsInitialBlockDownload()) nMinutes = 5; - bitdb.dbenv.txn_checkpoint(nMinutes ? GetArg("-dblogsize", 100)*1024 : 0, nMinutes, 0); + bitdb.dbenv.txn_checkpoint(nMinutes ? GetArgUInt("-dblogsize", 100)*1024 : 0, nMinutes, 0); { LOCK(bitdb.cs_db); @@ -400,7 +396,8 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) } Dbc* pcursor = db.GetCursor(); - if (pcursor) + if (pcursor) { + size_t pszSkipLen = strlen(pszSkip); while (fSuccess) { CDataStream ssKey(SER_DISK, CLIENT_VERSION); @@ -418,7 +415,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) break; } if (pszSkip && - strncmp(&ssKey[0], pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0) + strncmp(&ssKey[0], pszSkip, std::min(ssKey.size(), pszSkipLen)) == 0) continue; if (strncmp(&ssKey[0], "\x07version", 8) == 0) { @@ -432,6 +429,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) if (ret2 > 0) fSuccess = false; } + } if (fSuccess) { db.Close(); @@ -543,7 +541,7 @@ bool CAddrDB::Write(const CAddrMan& addr) try { fileout << ssPeers; } - catch (std::exception &e) { + catch (const std::exception&) { return error("CAddrman::Write() : I/O error"); } FileCommit(fileout); @@ -578,7 +576,7 @@ bool CAddrDB::Read(CAddrMan& addr) filein.read((char *)&vchData[0], dataSize); filein >> hashIn; } - catch (std::exception &e) { + catch (const std::exception&) { return error("CAddrman::Read() 2 : I/O error or stream data corrupted"); } filein.fclose(); @@ -602,7 +600,7 @@ bool CAddrDB::Read(CAddrMan& addr) // de-serialize address data into one CAddrMan object ssPeers >> addr; } - catch (std::exception &e) { + catch (const std::exception&) { return error("CAddrman::Read() : I/O error or stream data corrupted"); }