Skip to content

Commit

Permalink
Minor cleanups:
Browse files Browse the repository at this point in the history
* Make sure variables are always initialized
* Use lround instead of adding .5 and casting
* Remove some unneeded vars
* Check for null before calling strcmp
* Remove redundant if conditions
* Remove make_TxQ factory function
  • Loading branch information
seelabs committed Apr 28, 2020
1 parent 24d590c commit 4ee8a79
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ Ledger::rawInsert(std::shared_ptr<SLE> const& sle)
Serializer ss;
sle->add(ss);
auto item = std::make_shared<SHAMapItem const>(sle->key(), std::move(ss));
// addGiveItem should take ownership
if (!stateMap_->addGiveItem(std::move(item), false, false))
LogicError("Ledger::rawInsert: key already exists");
}
Expand All @@ -510,7 +509,7 @@ Ledger::rawReplace(std::shared_ptr<SLE> const& sle)
Serializer ss;
sle->add(ss);
auto item = std::make_shared<SHAMapItem const>(sle->key(), std::move(ss));
// updateGiveItem should take ownership

if (!stateMap_->updateGiveItem(std::move(item), false, false))
LogicError("Ledger::rawReplace: key not found");
}
Expand Down
7 changes: 4 additions & 3 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ class ApplicationImp : public Application, public RootStoppable, public BasicApp
, m_loadManager(
make_LoadManager(*this, *this, logs_->journal("LoadManager")))

, txQ_(make_TxQ(setup_TxQ(*config_), logs_->journal("TxQ")))
, txQ_(
std::make_unique<TxQ>(setup_TxQ(*config_), logs_->journal("TxQ")))

, sweepTimer_(get_io_service())

Expand Down Expand Up @@ -1843,8 +1844,8 @@ ApplicationImp::fdRequired() const
// Standard handles, config file, misc I/O etc:
int needed = 128;

// 1.5 times the configured peer limit for peer connections:
needed += static_cast<int>(0.5 + (1.5 * overlay_->limit()));
// 2x the configured peer limit for peer connections:
needed += 2 * overlay_->limit();

// the number of fds needed by the backend (internally
// doubled if online delete is enabled).
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class NetworkOPsImp final : public NetworkOPs
bool const admin;
bool const local;
FailHard const failType;
bool applied;
bool applied = false;
TER result;

TransactionStatus(
Expand Down
6 changes: 0 additions & 6 deletions src/ripple/app/misc/TxQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,6 @@ class TxQ
TxQ::Setup
setup_TxQ(Config const&);

/**
@ref TxQ object factory.
*/
std::unique_ptr<TxQ>
make_TxQ(TxQ::Setup const&, beast::Journal);

template <class T>
std::pair<bool, XRPAmount>
toDrops(FeeLevel<T> const& level, XRPAmount const& baseFee)
Expand Down
6 changes: 0 additions & 6 deletions src/ripple/app/misc/impl/TxQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,10 +1549,4 @@ setup_TxQ(Config const& config)
return setup;
}

std::unique_ptr<TxQ>
make_TxQ(TxQ::Setup const& setup, beast::Journal j)
{
return std::make_unique<TxQ>(setup, j);
}

} // namespace ripple
3 changes: 1 addition & 2 deletions src/ripple/basics/BasicConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,10 @@ get(Section const& section,
inline std::string
get(Section const& section, std::string const& name, const char* defaultValue)
{
bool found_and_valid = false;
try
{
auto const val = section.get<std::string>(name);
if ((found_and_valid = val.is_initialized()))
if (val.is_initialized())
return *val;
}
catch (boost::bad_lexical_cast&)
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/basics/impl/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ decode(void* dest, char const* src, std::size_t len)
{
char* out = static_cast<char*>(dest);
auto in = reinterpret_cast<unsigned char const*>(src);
unsigned char c3[3], c4[4];
unsigned char c3[3]{}, c4[4]{};
int i = 0;
int j = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/json/impl/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Value::CZString::~CZString()
bool
Value::CZString::operator<(const CZString& other) const
{
if (cstr_)
if (cstr_ && other.cstr_)
return strcmp(cstr_, other.cstr_) < 0;

return index_ < other.index_;
Expand All @@ -141,7 +141,7 @@ Value::CZString::operator<(const CZString& other) const
bool
Value::CZString::operator==(const CZString& other) const
{
if (cstr_)
if (cstr_ && other.cstr_)
return strcmp(cstr_, other.cstr_) == 0;

return index_ == other.index_;
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/impl/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ SerialIter::getFieldID(int& type, int& name)
{
// uncommon type
type = get8();
if (type == 0 || type < 16)
if (type < 16)
Throw<std::runtime_error>(
"gFID: uncommon type out of range " + std::to_string(type));
}
Expand All @@ -574,7 +574,7 @@ SerialIter::getFieldID(int& type, int& name)
{
// uncommon name
name = get8();
if (name == 0 || name < 16)
if (name < 16)
Throw<std::runtime_error>(
"gFID: uncommon name out of range " + std::to_string(name));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/app/PayStrand_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ struct ExistingElementPool
return STAmount{};
return (*sle)[sfBalance];
};
std::uint64_t totalXRP[2];
std::uint64_t totalXRP[2]{};
for (auto ai1 = accounts.begin(), aie = accounts.end(); ai1 != aie;
++ai1)
{
Expand Down
32 changes: 15 additions & 17 deletions src/test/nodestore/TestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,21 @@ class TestBase : public beast::unit_test::suite

for (int i = 0; i < numObjects; ++i)
{
NodeObjectType type;

switch (rand_int(rng, 3))
{
case 0:
type = hotLEDGER;
break;
case 1:
type = hotACCOUNT_NODE;
break;
case 2:
type = hotTRANSACTION_NODE;
break;
case 3:
type = hotUNKNOWN;
break;
}
NodeObjectType const type = [&] {
switch (rand_int(rng, 3))
{
case 0:
return hotLEDGER;
case 1:
return hotACCOUNT_NODE;
case 2:
return hotTRANSACTION_NODE;
case 3:
return hotUNKNOWN;
}
// will never happen, but make static analysys tool happy.
return hotUNKNOWN;
}();

uint256 hash;
beast::rngfill(hash.begin(), hash.size(), rng);
Expand Down

0 comments on commit 4ee8a79

Please sign in to comment.