Some code cleanups tagged by static analysis

This commit is contained in:
seelabs
2021-06-07 11:26:27 -04:00
committed by manojsdoshi
parent 78bc2727f7
commit cd27b5f2bd
28 changed files with 60 additions and 57 deletions

View File

@@ -141,7 +141,7 @@ public:
txs_iter_impl(txs_iter_impl const&) = default; txs_iter_impl(txs_iter_impl const&) = default;
txs_iter_impl(bool metadata, SHAMap::const_iterator iter) txs_iter_impl(bool metadata, SHAMap::const_iterator iter)
: metadata_(metadata), iter_(iter) : metadata_(metadata), iter_(std::move(iter))
{ {
} }

View File

@@ -31,7 +31,7 @@ namespace ripple {
class OrderBookDB class OrderBookDB
{ {
public: public:
OrderBookDB(Application& app); explicit OrderBookDB(Application& app);
void void
setup(std::shared_ptr<ReadView const> const& ledger); setup(std::shared_ptr<ReadView const> const& ledger);

View File

@@ -30,7 +30,7 @@ namespace ripple {
class NodeStoreScheduler : public NodeStore::Scheduler class NodeStoreScheduler : public NodeStore::Scheduler
{ {
public: public:
NodeStoreScheduler(JobQueue& jobQueue); explicit NodeStoreScheduler(JobQueue& jobQueue);
void void
scheduleTask(NodeStore::Task& task) override; scheduleTask(NodeStore::Task& task) override;

View File

@@ -374,7 +374,7 @@ public:
save( save(
DatabaseCon& dbCon, DatabaseCon& dbCon,
std::string const& dbTable, std::string const& dbTable,
std::function<bool(PublicKey const&)> isTrusted); std::function<bool(PublicKey const&)> const& isTrusted);
/** Invokes the callback once for every populated manifest. /** Invokes the callback once for every populated manifest.

View File

@@ -535,7 +535,7 @@ SHAMapStoreImp::makeBackendRotating(std::string path)
void void
SHAMapStoreImp::clearSql( SHAMapStoreImp::clearSql(
LedgerIndex lastRotated, LedgerIndex lastRotated,
const std::string TableName, std::string const& TableName,
std::function<std::optional<LedgerIndex>()> const& getMinSeq, std::function<std::optional<LedgerIndex>()> const& getMinSeq,
std::function<void(LedgerIndex)> const& deleteBeforeSeq) std::function<void(LedgerIndex)> const& deleteBeforeSeq)
{ {

View File

@@ -212,7 +212,7 @@ private:
void void
clearSql( clearSql(
LedgerIndex lastRotated, LedgerIndex lastRotated,
const std::string TableName, std::string const& TableName,
std::function<std::optional<LedgerIndex>()> const& getMinSeq, std::function<std::optional<LedgerIndex>()> const& getMinSeq,
std::function<void(LedgerIndex)> const& deleteBeforeSeq); std::function<void(LedgerIndex)> const& deleteBeforeSeq);
void void

View File

@@ -542,7 +542,7 @@ void
ManifestCache::save( ManifestCache::save(
DatabaseCon& dbCon, DatabaseCon& dbCon,
std::string const& dbTable, std::string const& dbTable,
std::function<bool(PublicKey const&)> isTrusted) std::function<bool(PublicKey const&)> const& isTrusted)
{ {
std::lock_guard lock{apply_mutex_}; std::lock_guard lock{apply_mutex_};
auto db = dbCon.checkoutDb(); auto db = dbCon.checkoutDb();

View File

@@ -122,14 +122,14 @@ public:
uint256 nodestoreHash; uint256 nodestoreHash;
AccountTransactionsData( AccountTransactionsData(
TxMeta& meta, TxMeta const& meta,
uint256&& nodestoreHash, uint256 const& nodestoreHash,
beast::Journal& j) beast::Journal j)
: accounts(meta.getAffectedAccounts(j)) : accounts(meta.getAffectedAccounts(j))
, ledgerSequence(meta.getLgrSeq()) , ledgerSequence(meta.getLgrSeq())
, transactionIndex(meta.getIndex()) , transactionIndex(meta.getIndex())
, txHash(meta.getTxID()) , txHash(meta.getTxID())
, nodestoreHash(std::move(nodestoreHash)) , nodestoreHash(nodestoreHash)
{ {
} }
}; };

View File

@@ -75,7 +75,7 @@ void
saveManifests( saveManifests(
soci::session& session, soci::session& session,
std::string const& dbTable, std::string const& dbTable,
std::function<bool(PublicKey const&)> isTrusted, std::function<bool(PublicKey const&)> const& isTrusted,
hash_map<PublicKey, Manifest> const& map, hash_map<PublicKey, Manifest> const& map,
beast::Journal j); beast::Journal j);
@@ -237,7 +237,7 @@ setLastRotated(soci::session& session, LedgerIndex seq);
std::pair<std::unique_ptr<DatabaseCon>, std::optional<std::uint64_t>> std::pair<std::unique_ptr<DatabaseCon>, std::optional<std::uint64_t>>
openDatabaseBodyDb( openDatabaseBodyDb(
DatabaseCon::Setup const& setup, DatabaseCon::Setup const& setup,
boost::filesystem::path path); boost::filesystem::path const& path);
/** /**
* @brief databaseBodyDoPut Saves new fragment of downloaded file. * @brief databaseBodyDoPut Saves new fragment of downloaded file.

View File

@@ -174,13 +174,13 @@ public:
bool bool
transactionDbHasSpace(Config const& config) override; transactionDbHasSpace(Config const& config) override;
int std::uint32_t
getKBUsedAll() override; getKBUsedAll() override;
int std::uint32_t
getKBUsedLedger() override; getKBUsedLedger() override;
int std::uint32_t
getKBUsedTransaction() override; getKBUsedTransaction() override;
void void
@@ -1473,7 +1473,7 @@ RelationalDBInterfaceSqliteImp::transactionDbHasSpace(Config const& config)
}); });
} }
int std::uint32_t
RelationalDBInterfaceSqliteImp::getKBUsedAll() RelationalDBInterfaceSqliteImp::getKBUsedAll()
{ {
/* if database exists, use it */ /* if database exists, use it */
@@ -1483,7 +1483,7 @@ RelationalDBInterfaceSqliteImp::getKBUsedAll()
} }
/* else use shard databases */ /* else use shard databases */
int sum = 0; std::uint32_t sum = 0;
iterateLedgerBack( iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) { {}, [&](soci::session& session, std::uint32_t shardIndex) {
sum += ripple::getKBUsedAll(session); sum += ripple::getKBUsedAll(session);
@@ -1492,7 +1492,7 @@ RelationalDBInterfaceSqliteImp::getKBUsedAll()
return sum; return sum;
} }
int std::uint32_t
RelationalDBInterfaceSqliteImp::getKBUsedLedger() RelationalDBInterfaceSqliteImp::getKBUsedLedger()
{ {
/* if database exists, use it */ /* if database exists, use it */
@@ -1502,7 +1502,7 @@ RelationalDBInterfaceSqliteImp::getKBUsedLedger()
} }
/* else use shard databases */ /* else use shard databases */
int sum = 0; std::uint32_t sum = 0;
iterateLedgerBack( iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) { {}, [&](soci::session& session, std::uint32_t shardIndex) {
sum += ripple::getKBUsedDB(session); sum += ripple::getKBUsedDB(session);
@@ -1511,7 +1511,7 @@ RelationalDBInterfaceSqliteImp::getKBUsedLedger()
return sum; return sum;
} }
int std::uint32_t
RelationalDBInterfaceSqliteImp::getKBUsedTransaction() RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
{ {
/* if database exists, use it */ /* if database exists, use it */
@@ -1521,7 +1521,7 @@ RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
} }
/* else use shard databases */ /* else use shard databases */
int sum = 0; std::uint32_t sum = 0;
iterateTransactionBack( iterateTransactionBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) { {}, [&](soci::session& session, std::uint32_t shardIndex) {
sum += ripple::getKBUsedDB(session); sum += ripple::getKBUsedDB(session);

View File

@@ -266,14 +266,14 @@ public:
* @brief getKBUsedAll Returns space used by all databases. * @brief getKBUsedAll Returns space used by all databases.
* @return Space in kilobytes. * @return Space in kilobytes.
*/ */
virtual int virtual uint32_t
getKBUsedAll() = 0; getKBUsedAll() = 0;
/** /**
* @brief getKBUsedLedger Returns space used by ledger database. * @brief getKBUsedLedger Returns space used by ledger database.
* @return Space in kilobytes. * @return Space in kilobytes.
*/ */
virtual int virtual uint32_t
getKBUsedLedger() = 0; getKBUsedLedger() = 0;
/** /**
@@ -281,7 +281,7 @@ public:
* database. * database.
* @return Space in kilobytes. * @return Space in kilobytes.
*/ */
virtual int virtual uint32_t
getKBUsedTransaction() = 0; getKBUsedTransaction() = 0;
/** /**

View File

@@ -104,7 +104,7 @@ void
saveManifests( saveManifests(
soci::session& session, soci::session& session,
std::string const& dbTable, std::string const& dbTable,
std::function<bool(PublicKey const&)> isTrusted, std::function<bool(PublicKey const&)> const& isTrusted,
hash_map<PublicKey, Manifest> const& map, hash_map<PublicKey, Manifest> const& map,
beast::Journal j) beast::Journal j)
{ {
@@ -410,7 +410,7 @@ setLastRotated(soci::session& session, LedgerIndex seq)
std::pair<std::unique_ptr<DatabaseCon>, std::optional<std::uint64_t>> std::pair<std::unique_ptr<DatabaseCon>, std::optional<std::uint64_t>>
openDatabaseBodyDb( openDatabaseBodyDb(
DatabaseCon::Setup const& setup, DatabaseCon::Setup const& setup,
boost::filesystem::path path) boost::filesystem::path const& path)
{ {
// SOCI requires boost::optional (not std::optional) as the parameter. // SOCI requires boost::optional (not std::optional) as the parameter.
boost::optional<std::string> pathFromDb; boost::optional<std::string> pathFromDb;

View File

@@ -266,7 +266,7 @@ private:
ThreadSafeQueue<std::shared_ptr<SLE>>& writeQueue); ThreadSafeQueue<std::shared_ptr<SLE>>& writeQueue);
public: public:
ReportingETL(Application& app); explicit ReportingETL(Application& app);
~ReportingETL() ~ReportingETL()
{ {

View File

@@ -57,7 +57,7 @@ class BasicConfig;
class DBConfig class DBConfig
{ {
std::string connectionString_; std::string connectionString_;
DBConfig(std::string const& dbPath); explicit DBConfig(std::string const& dbPath);
public: public:
DBConfig(BasicConfig const& config, std::string const& dbName); DBConfig(BasicConfig const& config, std::string const& dbName);
@@ -97,9 +97,9 @@ open(
std::string const& beName, std::string const& beName,
std::string const& connectionString); std::string const& connectionString);
size_t std::uint32_t
getKBUsedAll(soci::session& s); getKBUsedAll(soci::session& s);
size_t std::uint32_t
getKBUsedDB(soci::session& s); getKBUsedDB(soci::session& s);
void void

View File

@@ -126,7 +126,7 @@ getConnection(soci::session& s)
return result; return result;
} }
size_t std::uint32_t
getKBUsedAll(soci::session& s) getKBUsedAll(soci::session& s)
{ {
if (!getConnection(s)) if (!getConnection(s))
@@ -135,7 +135,7 @@ getKBUsedAll(soci::session& s)
sqlite_api::sqlite3_memory_used() / kilobytes(1)); sqlite_api::sqlite3_memory_used() / kilobytes(1));
} }
size_t std::uint32_t
getKBUsedDB(soci::session& s) getKBUsedDB(soci::session& s)
{ {
// This function will have to be customized when other backends are added // This function will have to be customized when other backends are added

View File

@@ -50,7 +50,7 @@ public:
TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&); TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&);
uint256 const& uint256 const&
getTxID() getTxID() const
{ {
return mTransactionID; return mTransactionID;
} }

View File

@@ -105,7 +105,7 @@ public:
*/ */
void void
open( open(
boost::filesystem::path path, boost::filesystem::path const& path,
Config const& config, Config const& config,
boost::asio::io_service& io_service, boost::asio::io_service& io_service,
boost::system::error_code& ec); boost::system::error_code& ec);
@@ -159,7 +159,7 @@ public:
put(ConstBufferSequence const& buffers, boost::system::error_code& ec); put(ConstBufferSequence const& buffers, boost::system::error_code& ec);
void void
do_put(std::string data); do_put(std::string const& data);
// This function is called when writing is complete. // This function is called when writing is complete.
// It is an opportunity to perform any final actions // It is an opportunity to perform any final actions

View File

@@ -43,7 +43,7 @@ DatabaseBody::value_type::close()
inline void inline void
DatabaseBody::value_type::open( DatabaseBody::value_type::open(
boost::filesystem::path path, boost::filesystem::path const& path,
Config const& config, Config const& config,
boost::asio::io_service& io_service, boost::asio::io_service& io_service,
boost::system::error_code& ec) boost::system::error_code& ec)
@@ -156,7 +156,7 @@ DatabaseBody::reader::put(
} }
inline void inline void
DatabaseBody::reader::do_put(std::string data) DatabaseBody::reader::do_put(std::string const& data)
{ {
using namespace boost::asio; using namespace boost::asio;

View File

@@ -970,7 +970,8 @@ DatabaseShardImp::doImportDatabase()
if (isStopping()) if (isStopping())
return; return;
auto const ledger{loadByIndex(*ledgerSeq, app_, false)}; // Not const so it may be moved later
auto ledger{loadByIndex(*ledgerSeq, app_, false)};
if (!ledger || ledger->info().seq != ledgerSeq) if (!ledger || ledger->info().seq != ledgerSeq)
break; break;

View File

@@ -1218,18 +1218,18 @@ Shard::Count
Shard::makeBackendCount() Shard::makeBackendCount()
{ {
if (stop_ || busy_) if (stop_ || busy_)
return {nullptr}; return Shard::Count{nullptr};
std::lock_guard lock(mutex_); std::lock_guard lock(mutex_);
if (!backend_) if (!backend_)
{ {
JLOG(j_.error()) << "shard " << index_ << " not initialized"; JLOG(j_.error()) << "shard " << index_ << " not initialized";
return {nullptr}; return Shard::Count{nullptr};
} }
if (!backend_->isOpen()) if (!backend_->isOpen())
{ {
if (!open(lock)) if (!open(lock))
return {nullptr}; return Shard::Count{nullptr};
} }
else if (state_ == ShardState::finalized) else if (state_ == ShardState::finalized)
lastAccess_ = std::chrono::steady_clock::now(); lastAccess_ = std::chrono::steady_clock::now();

View File

@@ -262,7 +262,8 @@ private:
other.counter_ = nullptr; other.counter_ = nullptr;
} }
Count(std::atomic<std::uint32_t>* counter) noexcept : counter_(counter) explicit Count(std::atomic<std::uint32_t>* counter) noexcept
: counter_(counter)
{ {
if (counter_) if (counter_)
++(*counter_); ++(*counter_);
@@ -274,7 +275,7 @@ private:
--(*counter_); --(*counter_);
} }
operator bool() const noexcept explicit operator bool() const noexcept
{ {
return counter_ != nullptr; return counter_ != nullptr;
} }

View File

@@ -134,7 +134,7 @@ public:
/** Create a quality from the ratio of two amounts. */ /** Create a quality from the ratio of two amounts. */
template <class In, class Out> template <class In, class Out>
Quality(TAmounts<In, Out> const& amount) explicit Quality(TAmounts<In, Out> const& amount)
: Quality(Amounts(toSTAmount(amount.in), toSTAmount(amount.out))) : Quality(Amounts(toSTAmount(amount.in), toSTAmount(amount.out)))
{ {
} }

View File

@@ -56,7 +56,7 @@ public:
static std::unique_ptr<ShardArchiveHandler> static std::unique_ptr<ShardArchiveHandler>
tryMakeRecoveryHandler(Application& app); tryMakeRecoveryHandler(Application& app);
ShardArchiveHandler(Application& app); explicit ShardArchiveHandler(Application& app);
virtual ~ShardArchiveHandler() = default; virtual ~ShardArchiveHandler() = default;
@@ -163,7 +163,7 @@ private:
class RecoveryHandler : public ShardArchiveHandler class RecoveryHandler : public ShardArchiveHandler
{ {
public: public:
RecoveryHandler(Application& app); explicit RecoveryHandler(Application& app);
}; };
} // namespace RPC } // namespace RPC

View File

@@ -75,7 +75,7 @@ getCountsJson(Application& app, int minObjectCount)
if (!app.config().reporting() && app.config().useTxTables()) if (!app.config().reporting() && app.config().useTxTables())
{ {
int dbKB = dynamic_cast<RelationalDBInterfaceSqlite*>( auto dbKB = dynamic_cast<RelationalDBInterfaceSqlite*>(
&app.getRelationalDBInterface()) &app.getRelationalDBInterface())
->getKBUsedAll(); ->getKBUsedAll();

View File

@@ -63,7 +63,7 @@ doTxHistory(RPC::JsonContext& context)
if (context.app.config().reporting()) if (context.app.config().reporting())
obj["used_postgres"] = true; obj["used_postgres"] = true;
for (auto t : trans) for (auto const& t : trans)
txs.append(t->getJson(JsonOptions::none)); txs.append(t->getJson(JsonOptions::none));
return obj; return obj;

View File

@@ -191,7 +191,8 @@ public:
} }
Handler const* Handler const*
getHandler(unsigned version, bool betaEnabled, std::string name) const getHandler(unsigned version, bool betaEnabled, std::string const& name)
const
{ {
if (version < RPC::apiMinimumSupportedVersion || if (version < RPC::apiMinimumSupportedVersion ||
version > (betaEnabled ? RPC::apiBetaVersion version > (betaEnabled ? RPC::apiBetaVersion

View File

@@ -52,7 +52,7 @@ class PerfLog_test : public beast::unit_test::suite
beast::Journal j_; beast::Journal j_;
bool stopSignaled{false}; bool stopSignaled{false};
Fixture(beast::Journal const& j) : j_(j) explicit Fixture(beast::Journal j) : j_(j)
{ {
} }

View File

@@ -1193,7 +1193,7 @@ class DatabaseShard_test : public TestBase
for (std::uint32_t i = 1; i <= 2; ++i) for (std::uint32_t i = 1; i <= 2; ++i)
waitShard(*db, i); waitShard(*db, i);
auto const finalShards{std::move(db->getShardInfo()->finalized())}; auto const finalShards{db->getShardInfo()->finalized()};
for (std::uint32_t shardIndex : {1, 2}) for (std::uint32_t shardIndex : {1, 2})
BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex)); BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex));
} }
@@ -1209,7 +1209,7 @@ class DatabaseShard_test : public TestBase
for (std::uint32_t i = 1; i <= 2; ++i) for (std::uint32_t i = 1; i <= 2; ++i)
waitShard(*db, i); waitShard(*db, i);
auto const finalShards{std::move(db->getShardInfo()->finalized())}; auto const finalShards{db->getShardInfo()->finalized()};
for (std::uint32_t shardIndex : {1, 2}) for (std::uint32_t shardIndex : {1, 2})
BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex)); BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex));
@@ -1358,7 +1358,7 @@ class DatabaseShard_test : public TestBase
for (std::uint32_t i = 1; i <= shardCount; ++i) for (std::uint32_t i = 1; i <= shardCount; ++i)
waitShard(*db, i); waitShard(*db, i);
auto const final{std::move(db->getShardInfo()->finalized())}; auto const final{db->getShardInfo()->finalized()};
for (std::uint32_t shardIndex : {1, 2, 3, 4}) for (std::uint32_t shardIndex : {1, 2, 3, 4})
BEAST_EXPECT(boost::icl::contains(final, shardIndex)); BEAST_EXPECT(boost::icl::contains(final, shardIndex));
@@ -1417,7 +1417,7 @@ class DatabaseShard_test : public TestBase
for (std::uint32_t i = 1; i <= shardCount; ++i) for (std::uint32_t i = 1; i <= shardCount; ++i)
waitShard(*db, i); waitShard(*db, i);
auto const finalShards{std::move(db->getShardInfo()->finalized())}; auto const finalShards{db->getShardInfo()->finalized()};
for (std::uint32_t shardIndex : {1, 2, 3, 4}) for (std::uint32_t shardIndex : {1, 2, 3, 4})
BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex)); BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex));