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(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
{
public:
OrderBookDB(Application& app);
explicit OrderBookDB(Application& app);
void
setup(std::shared_ptr<ReadView const> const& ledger);

View File

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

View File

@@ -374,7 +374,7 @@ public:
save(
DatabaseCon& dbCon,
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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -126,7 +126,7 @@ getConnection(soci::session& s)
return result;
}
size_t
std::uint32_t
getKBUsedAll(soci::session& s)
{
if (!getConnection(s))
@@ -135,7 +135,7 @@ getKBUsedAll(soci::session& s)
sqlite_api::sqlite3_memory_used() / kilobytes(1));
}
size_t
std::uint32_t
getKBUsedDB(soci::session& s)
{
// 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&);
uint256 const&
getTxID()
getTxID() const
{
return mTransactionID;
}

View File

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

View File

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

View File

@@ -970,7 +970,8 @@ DatabaseShardImp::doImportDatabase()
if (isStopping())
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)
break;

View File

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

View File

@@ -262,7 +262,8 @@ private:
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_)
++(*counter_);
@@ -274,7 +275,7 @@ private:
--(*counter_);
}
operator bool() const noexcept
explicit operator bool() const noexcept
{
return counter_ != nullptr;
}

View File

@@ -134,7 +134,7 @@ public:
/** Create a quality from the ratio of two amounts. */
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)))
{
}

View File

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

View File

@@ -75,9 +75,9 @@ getCountsJson(Application& app, int minObjectCount)
if (!app.config().reporting() && app.config().useTxTables())
{
int dbKB = dynamic_cast<RelationalDBInterfaceSqlite*>(
&app.getRelationalDBInterface())
->getKBUsedAll();
auto dbKB = dynamic_cast<RelationalDBInterfaceSqlite*>(
&app.getRelationalDBInterface())
->getKBUsedAll();
if (dbKB > 0)
ret[jss::dbKBTotal] = dbKB;

View File

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

View File

@@ -191,7 +191,8 @@ public:
}
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 ||
version > (betaEnabled ? RPC::apiBetaVersion

View File

@@ -52,7 +52,7 @@ class PerfLog_test : public beast::unit_test::suite
beast::Journal j_;
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)
waitShard(*db, i);
auto const finalShards{std::move(db->getShardInfo()->finalized())};
auto const finalShards{db->getShardInfo()->finalized()};
for (std::uint32_t shardIndex : {1, 2})
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)
waitShard(*db, i);
auto const finalShards{std::move(db->getShardInfo()->finalized())};
auto const finalShards{db->getShardInfo()->finalized()};
for (std::uint32_t shardIndex : {1, 2})
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)
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})
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)
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})
BEAST_EXPECT(boost::icl::contains(finalShards, shardIndex));