mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cleanups and fixes (RIPD-532):
* Properly handle sfWalletLocator field * Plug a tiny memory leak * Avoid naked pointers * Remove unused variables * Other small cleanups
This commit is contained in:
@@ -85,17 +85,19 @@ private:
|
|||||||
typedef typename map_type::iterator iterator;
|
typedef typename map_type::iterator iterator;
|
||||||
typedef std::lock_guard <Mutex> lock_guard;
|
typedef std::lock_guard <Mutex> lock_guard;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename map_type::size_type size_type;
|
||||||
|
|
||||||
|
private:
|
||||||
Mutex mutable m_mutex;
|
Mutex mutable m_mutex;
|
||||||
map_type m_map;
|
map_type m_map;
|
||||||
Stats mutable m_stats;
|
Stats mutable m_stats;
|
||||||
clock_type& m_clock;
|
clock_type& m_clock;
|
||||||
std::string const m_name;
|
std::string const m_name;
|
||||||
unsigned int m_target_size;
|
size_type m_target_size;
|
||||||
clock_type::duration m_target_age;
|
clock_type::duration m_target_age;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef typename map_type::size_type size_type;
|
|
||||||
|
|
||||||
/** Construct with the specified name.
|
/** Construct with the specified name.
|
||||||
|
|
||||||
@param size The initial target size.
|
@param size The initial target size.
|
||||||
@@ -112,7 +114,6 @@ public:
|
|||||||
, m_target_size (target_size)
|
, m_target_size (target_size)
|
||||||
, m_target_age (std::chrono::seconds (expiration_seconds))
|
, m_target_age (std::chrono::seconds (expiration_seconds))
|
||||||
{
|
{
|
||||||
assert (m_target_size >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VFALCO TODO Use a forwarding constructor call here
|
// VFALCO TODO Use a forwarding constructor call here
|
||||||
@@ -126,7 +127,6 @@ public:
|
|||||||
, m_target_size (target_size)
|
, m_target_size (target_size)
|
||||||
, m_target_age (std::chrono::seconds (expiration_seconds))
|
, m_target_age (std::chrono::seconds (expiration_seconds))
|
||||||
{
|
{
|
||||||
assert (m_target_size >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ void
|
|||||||
ServerImpl::remove (Door& door)
|
ServerImpl::remove (Door& door)
|
||||||
{
|
{
|
||||||
std::lock_guard <std::mutex> lock (mutex_);
|
std::lock_guard <std::mutex> lock (mutex_);
|
||||||
state_.doors.push_back (door);
|
state_.doors.erase (state_.doors.iterator_to (door));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -643,8 +643,8 @@ Reader::readArray ( Token& tokenStart )
|
|||||||
ok = readToken ( token );
|
ok = readToken ( token );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool badTokenType = ( token.type_ == tokenArraySeparator &&
|
bool badTokenType = ( token.type_ != tokenArraySeparator &&
|
||||||
token.type_ == tokenArrayEnd );
|
token.type_ != tokenArrayEnd );
|
||||||
|
|
||||||
if ( !ok || badTokenType )
|
if ( !ok || badTokenType )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
{
|
{
|
||||||
return mAborted || isComplete () || isFailed ();
|
return mAborted || isComplete () || isFailed ();
|
||||||
}
|
}
|
||||||
Ledger::ref getLedger ()
|
Ledger::ref getLedger () const
|
||||||
{
|
{
|
||||||
return mLedger;
|
return mLedger;
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
{
|
{
|
||||||
mAborted = true;
|
mAborted = true;
|
||||||
}
|
}
|
||||||
std::uint32_t getSeq ()
|
std::uint32_t getSeq () const
|
||||||
{
|
{
|
||||||
return mSeq;
|
return mSeq;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ public:
|
|||||||
int mFillInProgress;
|
int mFillInProgress;
|
||||||
|
|
||||||
int mPathFindThread; // Pathfinder jobs dispatched
|
int mPathFindThread; // Pathfinder jobs dispatched
|
||||||
bool mPathFindNewLedger;
|
|
||||||
bool mPathFindNewRequest;
|
bool mPathFindNewRequest;
|
||||||
|
|
||||||
std::atomic <std::uint32_t> mPubLedgerClose;
|
std::atomic <std::uint32_t> mPubLedgerClose;
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ public:
|
|||||||
return
|
return
|
||||||
std::addressof(mEntrySet) == std::addressof(other.mEntrySet) &&
|
std::addressof(mEntrySet) == std::addressof(other.mEntrySet) &&
|
||||||
mDirectoryIterator == other.mDirectoryIterator &&
|
mDirectoryIterator == other.mDirectoryIterator &&
|
||||||
mOfferIterator == mOfferIterator;
|
mOfferIterator == other.mOfferIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -158,14 +158,10 @@ bool LocalCredentials::dataStore (std::string const& strKey, std::string const&
|
|||||||
|
|
||||||
auto sl (getApp().getRpcDB ()->lock ());
|
auto sl (getApp().getRpcDB ()->lock ());
|
||||||
|
|
||||||
bool bSuccess = false;
|
|
||||||
|
|
||||||
return (db->executeSQL (str (boost::format ("REPLACE INTO RPCData (Key, Value) VALUES (%s,%s);")
|
return (db->executeSQL (str (boost::format ("REPLACE INTO RPCData (Key, Value) VALUES (%s,%s);")
|
||||||
% sqlEscape (strKey)
|
% sqlEscape (strKey)
|
||||||
% sqlEscape (strValue)
|
% sqlEscape (strValue)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
return bSuccess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ void PathState::reset(STAmount const& in, STAmount const& out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return true, iff lhs has less priority than rhs.
|
// Return true, iff lhs has less priority than rhs.
|
||||||
bool PathState::lessPriority (PathState& lhs, PathState& rhs)
|
bool PathState::lessPriority (PathState const& lhs, PathState const& rhs)
|
||||||
{
|
{
|
||||||
// First rank is quality.
|
// First rank is quality.
|
||||||
if (lhs.uQuality != rhs.uQuality)
|
if (lhs.uQuality != rhs.uQuality)
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ class PathState : public CountedObject <PathState>
|
|||||||
typedef std::vector<Ptr> List;
|
typedef std::vector<Ptr> List;
|
||||||
|
|
||||||
PathState (STAmount const& saSend, STAmount const& saSendMax)
|
PathState (STAmount const& saSend, STAmount const& saSendMax)
|
||||||
: saInReq (saSendMax)
|
: mIndex (0)
|
||||||
|
, uQuality (0)
|
||||||
|
, saInReq (saSendMax)
|
||||||
, saOutReq (saSend)
|
, saOutReq (saSend)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -99,7 +101,7 @@ class PathState : public CountedObject <PathState>
|
|||||||
Account const& sourceAccountID);
|
Account const& sourceAccountID);
|
||||||
void checkFreeze ();
|
void checkFreeze ();
|
||||||
|
|
||||||
static bool lessPriority (PathState& lhs, PathState& rhs);
|
static bool lessPriority (PathState const& lhs, PathState const& rhs);
|
||||||
|
|
||||||
LedgerEntrySet& ledgerEntries() { return lesEntries; }
|
LedgerEntrySet& ledgerEntries() { return lesEntries; }
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ public:
|
|||||||
std::uint32_t getQualityIn () const
|
std::uint32_t getQualityIn () const
|
||||||
{
|
{
|
||||||
return ((std::uint32_t) (mViewLowest ? mLowQualityIn : mHighQualityIn));
|
return ((std::uint32_t) (mViewLowest ? mLowQualityIn : mHighQualityIn));
|
||||||
return ((std::uint32_t) (mViewLowest ? mLowQualityIn : mHighQualityIn));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t getQualityOut () const
|
std::uint32_t getQualityOut () const
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public:
|
|||||||
if (!uHash)
|
if (!uHash)
|
||||||
{
|
{
|
||||||
m_journal.trace << "unset wallet locator";
|
m_journal.trace << "unset wallet locator";
|
||||||
mTxnAccount->makeFieldAbsent (sfEmailHash);
|
mTxnAccount->makeFieldAbsent (sfWalletLocator);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,27 +69,27 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 const& getID ()
|
uint256 const& getID () const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t getSeq ()
|
std::uint32_t getSeq () const
|
||||||
{
|
{
|
||||||
return m_seq;
|
return m_seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isExpired (LedgerIndex i)
|
bool isExpired (LedgerIndex i) const
|
||||||
{
|
{
|
||||||
return i > m_expire;
|
return i > m_expire;
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializedTransaction::ref getTX ()
|
SerializedTransaction::ref getTX () const
|
||||||
{
|
{
|
||||||
return m_txn;
|
return m_txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
RippleAddress const& getAccount ()
|
RippleAddress const& getAccount () const
|
||||||
{
|
{
|
||||||
return m_account;
|
return m_account;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ EC_KEY* CKey::GenerateRootPubKey (BIGNUM* pubGenerator)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --> public generator
|
// --> public generator
|
||||||
static BIGNUM* makeHash (RippleAddress const& pubGen, int seq, BIGNUM* order)
|
static BIGNUM* makeHash (RippleAddress const& pubGen, int seq, BIGNUM const* order)
|
||||||
{
|
{
|
||||||
int subSeq = 0;
|
int subSeq = 0;
|
||||||
BIGNUM* ret = nullptr;
|
BIGNUM* ret = nullptr;
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ char const* RFC1751::s_dictionary [2048] =
|
|||||||
|
|
||||||
/* Extract 'length' bits from the char array 's'
|
/* Extract 'length' bits from the char array 's'
|
||||||
starting with bit 'start' */
|
starting with bit 'start' */
|
||||||
unsigned long RFC1751::extract (char* s, int start, int length)
|
unsigned long RFC1751::extract (char const* s, int start, int length)
|
||||||
{
|
{
|
||||||
unsigned char cl;
|
unsigned char cl;
|
||||||
unsigned char cc;
|
unsigned char cc;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
static beast::String getWordFromBlob (void const* data, size_t bytes);
|
static beast::String getWordFromBlob (void const* data, size_t bytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static unsigned long extract (char* s, int start, int length);
|
static unsigned long extract (char const* s, int start, int length);
|
||||||
static void btoe (std::string& strHuman, std::string const& strData);
|
static void btoe (std::string& strHuman, std::string const& strData);
|
||||||
static void insert (char* s, int x, int start, int length);
|
static void insert (char* s, int x, int start, int length);
|
||||||
static void standard (std::string& strWord);
|
static void standard (std::string& strWord);
|
||||||
|
|||||||
@@ -438,19 +438,23 @@ int STAmount::compare (STAmount const& a) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STAmount* STAmount::construct (SerializerIterator& sit, SField::ref name)
|
std::unique_ptr<STAmount>
|
||||||
|
STAmount::construct (SerializerIterator& sit, SField::ref name)
|
||||||
{
|
{
|
||||||
std::uint64_t value = sit.get64 ();
|
std::uint64_t value = sit.get64 ();
|
||||||
|
|
||||||
|
// native
|
||||||
if ((value & cNotNative) == 0)
|
if ((value & cNotNative) == 0)
|
||||||
{
|
{
|
||||||
// native
|
// positive
|
||||||
if ((value & cPosNative) != 0)
|
if ((value & cPosNative) != 0)
|
||||||
return new STAmount (name, value & ~cPosNative, false); // positive
|
return std::make_unique<STAmount> (name, value & ~cPosNative, false);
|
||||||
else if (value == 0)
|
|
||||||
|
// negative
|
||||||
|
if (value == 0)
|
||||||
throw std::runtime_error ("negative zero is not canonical");
|
throw std::runtime_error ("negative zero is not canonical");
|
||||||
|
|
||||||
return new STAmount (name, value, true); // negative
|
return std::make_unique<STAmount> (name, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Issue issue;
|
Issue issue;
|
||||||
@@ -482,13 +486,13 @@ STAmount* STAmount::construct (SerializerIterator& sit, SField::ref name)
|
|||||||
throw std::runtime_error ("invalid currency value");
|
throw std::runtime_error ("invalid currency value");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new STAmount (name, issue, value, offset, isNegative);
|
return std::make_unique<STAmount> (name, issue, value, offset, isNegative);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset != 512)
|
if (offset != 512)
|
||||||
throw std::runtime_error ("invalid currency value");
|
throw std::runtime_error ("invalid currency value");
|
||||||
|
|
||||||
return new STAmount (name, issue);
|
return std::make_unique<STAmount> (name, issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int64_t STAmount::getSNValue () const
|
std::int64_t STAmount::getSNValue () const
|
||||||
@@ -1046,12 +1050,12 @@ STAmount STAmount::getPay (
|
|||||||
|
|
||||||
STAmount STAmount::deserialize (SerializerIterator& it)
|
STAmount STAmount::deserialize (SerializerIterator& it)
|
||||||
{
|
{
|
||||||
auto s = dynamic_cast<STAmount*> (construct (it, sfGeneric));
|
auto s = construct (it, sfGeneric);
|
||||||
|
|
||||||
if (!s)
|
if (!s)
|
||||||
throw std::runtime_error("Deserialization error");
|
throw std::runtime_error("Deserialization error");
|
||||||
|
|
||||||
STAmount ret (*s);
|
return STAmount (*s);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string STAmount::getFullText () const
|
std::string STAmount::getFullText () const
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <ripple/module/data/protocol/Serializer.h>
|
#include <ripple/module/data/protocol/Serializer.h>
|
||||||
#include <ripple/module/data/protocol/SerializedType.h>
|
#include <ripple/module/data/protocol/SerializedType.h>
|
||||||
|
|
||||||
|
#include <beast/cxx14/memory.h> // <memory>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
// Internal form:
|
// Internal form:
|
||||||
@@ -128,7 +130,7 @@ public:
|
|||||||
static std::unique_ptr<SerializedType> deserialize (
|
static std::unique_ptr<SerializedType> deserialize (
|
||||||
SerializerIterator& sit, SField::ref name)
|
SerializerIterator& sit, SField::ref name)
|
||||||
{
|
{
|
||||||
return std::unique_ptr<SerializedType> (construct (sit, name));
|
return construct (sit, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bSetJson (Json::Value const& jvSource);
|
bool bSetJson (Json::Value const& jvSource);
|
||||||
@@ -406,7 +408,10 @@ private:
|
|||||||
{
|
{
|
||||||
return new STAmount (*this);
|
return new STAmount (*this);
|
||||||
}
|
}
|
||||||
static STAmount* construct (SerializerIterator&, SField::ref name);
|
|
||||||
|
static
|
||||||
|
std::unique_ptr<STAmount>
|
||||||
|
construct (SerializerIterator&, SField::ref name);
|
||||||
|
|
||||||
STAmount (SField::ref name, Issue const& issue,
|
STAmount (SField::ref name, Issue const& issue,
|
||||||
std::uint64_t val, int off, bool isNat, bool negative)
|
std::uint64_t val, int off, bool isNat, bool negative)
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ void STAmount::canonicalizeRound (
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
WriteLog (lsTRACE, STAmount)
|
WriteLog (lsTRACE, STAmount)
|
||||||
<< "canonicalize< " << value
|
<< "canonicalizeRound< " << value << ":" << offset;
|
||||||
<< ":" << offset << (roundUp ? " up" : " down");
|
|
||||||
|
|
||||||
if (isNative)
|
if (isNative)
|
||||||
{
|
{
|
||||||
@@ -61,8 +60,7 @@ void STAmount::canonicalizeRound (
|
|||||||
}
|
}
|
||||||
|
|
||||||
WriteLog (lsTRACE, STAmount)
|
WriteLog (lsTRACE, STAmount)
|
||||||
<< "canonicalize> " << value
|
<< "canonicalizeRound> " << value << ":" << offset;
|
||||||
<< ":" << offset << (roundUp ? " up" : " down");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STAmount STAmount::addRound (STAmount const& v1, STAmount const& v2, bool roundUp)
|
STAmount STAmount::addRound (STAmount const& v1, STAmount const& v2, bool roundUp)
|
||||||
|
|||||||
@@ -59,11 +59,6 @@ Json::Value lookupLedger (
|
|||||||
jsonHash = params[jss::ledger];
|
jsonHash = params[jss::ledger];
|
||||||
jsonIndex = Json::Value ("");
|
jsonIndex = Json::Value ("");
|
||||||
}
|
}
|
||||||
else if (params[jss::ledger].isNumeric ())
|
|
||||||
{
|
|
||||||
jsonIndex = params[jss::ledger];
|
|
||||||
jsonHash = Json::Value ("0");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jsonIndex = params[jss::ledger];
|
jsonIndex = params[jss::ledger];
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ Bootcache::Bootcache (
|
|||||||
, m_clock (clock)
|
, m_clock (clock)
|
||||||
, m_journal (journal)
|
, m_journal (journal)
|
||||||
, m_whenUpdate (m_clock.now ())
|
, m_whenUpdate (m_clock.now ())
|
||||||
|
, m_needsUpdate (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ std::string to_string(Currency const& currency)
|
|||||||
{
|
{
|
||||||
static Currency const sIsoBits ("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF");
|
static Currency const sIsoBits ("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF");
|
||||||
|
|
||||||
// Characters we are willing to include the ASCII representation
|
// Characters we are willing to allow in the ASCII representation of a
|
||||||
// of a three-letter currency code
|
// three-letter currency code.
|
||||||
static std::string legalASCIICurrencyCharacters =
|
static std::string const allowed_characters =
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"0123456789"
|
"0123456789"
|
||||||
@@ -59,16 +59,13 @@ std::string to_string(Currency const& currency)
|
|||||||
// Specifying the system currency code using ISO-style representation
|
// Specifying the system currency code using ISO-style representation
|
||||||
// is not allowed.
|
// is not allowed.
|
||||||
if ((iso != systemCurrencyCode()) &&
|
if ((iso != systemCurrencyCode()) &&
|
||||||
(iso.find_first_not_of (legalASCIICurrencyCharacters) == std::string::npos))
|
(iso.find_first_not_of (allowed_characters) == std::string::npos))
|
||||||
{
|
{
|
||||||
return iso;
|
return iso;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint160 simple;
|
return strHex (currency.begin (), currency.size ());
|
||||||
simple.copyFrom(currency);
|
|
||||||
|
|
||||||
return to_string(simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool to_currency(Currency& currency, std::string const& code)
|
bool to_currency(Currency& currency, std::string const& code)
|
||||||
|
|||||||
Reference in New Issue
Block a user