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:
Nik Bougalis
2014-08-31 00:07:02 -07:00
parent 22ca13bc78
commit 56c18f7768
21 changed files with 54 additions and 58 deletions

View File

@@ -85,17 +85,19 @@ private:
typedef typename map_type::iterator iterator;
typedef std::lock_guard <Mutex> lock_guard;
public:
typedef typename map_type::size_type size_type;
private:
Mutex mutable m_mutex;
map_type m_map;
Stats mutable m_stats;
clock_type& m_clock;
std::string const m_name;
unsigned int m_target_size;
size_type m_target_size;
clock_type::duration m_target_age;
public:
typedef typename map_type::size_type size_type;
/** Construct with the specified name.
@param size The initial target size.
@@ -112,7 +114,6 @@ public:
, m_target_size (target_size)
, m_target_age (std::chrono::seconds (expiration_seconds))
{
assert (m_target_size >= 0);
}
// VFALCO TODO Use a forwarding constructor call here
@@ -126,7 +127,6 @@ public:
, m_target_size (target_size)
, m_target_age (std::chrono::seconds (expiration_seconds))
{
assert (m_target_size >= 0);
}
//--------------------------------------------------------------------------

View File

@@ -132,7 +132,7 @@ void
ServerImpl::remove (Door& door)
{
std::lock_guard <std::mutex> lock (mutex_);
state_.doors.push_back (door);
state_.doors.erase (state_.doors.iterator_to (door));
}
//--------------------------------------------------------------------------

View File

@@ -643,8 +643,8 @@ Reader::readArray ( Token& tokenStart )
ok = readToken ( token );
}
bool badTokenType = ( token.type_ == tokenArraySeparator &&
token.type_ == tokenArrayEnd );
bool badTokenType = ( token.type_ != tokenArraySeparator &&
token.type_ != tokenArrayEnd );
if ( !ok || badTokenType )
{

View File

@@ -66,7 +66,7 @@ public:
{
return mAborted || isComplete () || isFailed ();
}
Ledger::ref getLedger ()
Ledger::ref getLedger () const
{
return mLedger;
}
@@ -74,7 +74,7 @@ public:
{
mAborted = true;
}
std::uint32_t getSeq ()
std::uint32_t getSeq () const
{
return mSeq;
}

View File

@@ -68,7 +68,6 @@ public:
int mFillInProgress;
int mPathFindThread; // Pathfinder jobs dispatched
bool mPathFindNewLedger;
bool mPathFindNewRequest;
std::atomic <std::uint32_t> mPubLedgerClose;

View File

@@ -215,7 +215,7 @@ public:
return
std::addressof(mEntrySet) == std::addressof(other.mEntrySet) &&
mDirectoryIterator == other.mDirectoryIterator &&
mOfferIterator == mOfferIterator;
mOfferIterator == other.mOfferIterator;
}
bool

View File

@@ -158,14 +158,10 @@ bool LocalCredentials::dataStore (std::string const& strKey, std::string const&
auto sl (getApp().getRpcDB ()->lock ());
bool bSuccess = false;
return (db->executeSQL (str (boost::format ("REPLACE INTO RPCData (Key, Value) VALUES (%s,%s);")
% sqlEscape (strKey)
% sqlEscape (strValue)
)));
return bSuccess;
}
} // ripple

View File

@@ -64,7 +64,7 @@ void PathState::reset(STAmount const& in, STAmount const& out)
}
// 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.
if (lhs.uQuality != rhs.uQuality)

View File

@@ -34,7 +34,9 @@ class PathState : public CountedObject <PathState>
typedef std::vector<Ptr> List;
PathState (STAmount const& saSend, STAmount const& saSendMax)
: saInReq (saSendMax)
: mIndex (0)
, uQuality (0)
, saInReq (saSendMax)
, saOutReq (saSend)
{
}
@@ -99,7 +101,7 @@ class PathState : public CountedObject <PathState>
Account const& sourceAccountID);
void checkFreeze ();
static bool lessPriority (PathState& lhs, PathState& rhs);
static bool lessPriority (PathState const& lhs, PathState const& rhs);
LedgerEntrySet& ledgerEntries() { return lesEntries; }

View File

@@ -106,7 +106,6 @@ public:
std::uint32_t getQualityIn () const
{
return ((std::uint32_t) (mViewLowest ? mLowQualityIn : mHighQualityIn));
return ((std::uint32_t) (mViewLowest ? mLowQualityIn : mHighQualityIn));
}
std::uint32_t getQualityOut () const

View File

@@ -234,7 +234,7 @@ public:
if (!uHash)
{
m_journal.trace << "unset wallet locator";
mTxnAccount->makeFieldAbsent (sfEmailHash);
mTxnAccount->makeFieldAbsent (sfWalletLocator);
}
else
{

View File

@@ -69,27 +69,27 @@ public:
}
}
uint256 const& getID ()
uint256 const& getID () const
{
return m_id;
}
std::uint32_t getSeq ()
std::uint32_t getSeq () const
{
return m_seq;
}
bool isExpired (LedgerIndex i)
bool isExpired (LedgerIndex i) const
{
return i > m_expire;
}
SerializedTransaction::ref getTX ()
SerializedTransaction::ref getTX () const
{
return m_txn;
}
RippleAddress const& getAccount ()
RippleAddress const& getAccount () const
{
return m_account;
}

View File

@@ -189,7 +189,7 @@ EC_KEY* CKey::GenerateRootPubKey (BIGNUM* pubGenerator)
}
// --> 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;
BIGNUM* ret = nullptr;

View File

@@ -251,7 +251,7 @@ char const* RFC1751::s_dictionary [2048] =
/* Extract 'length' bits from the char array 's'
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 cc;

View File

@@ -39,7 +39,7 @@ public:
static beast::String getWordFromBlob (void const* data, size_t bytes);
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 insert (char* s, int x, int start, int length);
static void standard (std::string& strWord);

View File

@@ -438,19 +438,23 @@ int STAmount::compare (STAmount const& a) const
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 ();
// native
if ((value & cNotNative) == 0)
{
// native
// positive
if ((value & cPosNative) != 0)
return new STAmount (name, value & ~cPosNative, false); // positive
else if (value == 0)
return std::make_unique<STAmount> (name, value & ~cPosNative, false);
// negative
if (value == 0)
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;
@@ -482,13 +486,13 @@ STAmount* STAmount::construct (SerializerIterator& sit, SField::ref name)
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)
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
@@ -1046,12 +1050,12 @@ STAmount STAmount::getPay (
STAmount STAmount::deserialize (SerializerIterator& it)
{
auto s = dynamic_cast<STAmount*> (construct (it, sfGeneric));
auto s = construct (it, sfGeneric);
if (!s)
throw std::runtime_error("Deserialization error");
STAmount ret (*s);
return ret;
return STAmount (*s);
}
std::string STAmount::getFullText () const

View File

@@ -24,6 +24,8 @@
#include <ripple/module/data/protocol/Serializer.h>
#include <ripple/module/data/protocol/SerializedType.h>
#include <beast/cxx14/memory.h> // <memory>
namespace ripple {
// Internal form:
@@ -128,7 +130,7 @@ public:
static std::unique_ptr<SerializedType> deserialize (
SerializerIterator& sit, SField::ref name)
{
return std::unique_ptr<SerializedType> (construct (sit, name));
return construct (sit, name);
}
bool bSetJson (Json::Value const& jvSource);
@@ -406,7 +408,10 @@ private:
{
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,
std::uint64_t val, int off, bool isNat, bool negative)

View File

@@ -26,8 +26,7 @@ void STAmount::canonicalizeRound (
return;
WriteLog (lsTRACE, STAmount)
<< "canonicalize< " << value
<< ":" << offset << (roundUp ? " up" : " down");
<< "canonicalizeRound< " << value << ":" << offset;
if (isNative)
{
@@ -61,8 +60,7 @@ void STAmount::canonicalizeRound (
}
WriteLog (lsTRACE, STAmount)
<< "canonicalize> " << value
<< ":" << offset << (roundUp ? " up" : " down");
<< "canonicalizeRound> " << value << ":" << offset;
}
STAmount STAmount::addRound (STAmount const& v1, STAmount const& v2, bool roundUp)

View File

@@ -59,11 +59,6 @@ Json::Value lookupLedger (
jsonHash = params[jss::ledger];
jsonIndex = Json::Value ("");
}
else if (params[jss::ledger].isNumeric ())
{
jsonIndex = params[jss::ledger];
jsonHash = Json::Value ("0");
}
else
{
jsonIndex = params[jss::ledger];

View File

@@ -30,6 +30,7 @@ Bootcache::Bootcache (
, m_clock (clock)
, m_journal (journal)
, m_whenUpdate (m_clock.now ())
, m_needsUpdate (false)
{
}

View File

@@ -33,9 +33,9 @@ std::string to_string(Currency const& currency)
{
static Currency const sIsoBits ("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF");
// Characters we are willing to include the ASCII representation
// of a three-letter currency code
static std::string legalASCIICurrencyCharacters =
// Characters we are willing to allow in the ASCII representation of a
// three-letter currency code.
static std::string const allowed_characters =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
@@ -59,16 +59,13 @@ std::string to_string(Currency const& currency)
// Specifying the system currency code using ISO-style representation
// is not allowed.
if ((iso != systemCurrencyCode()) &&
(iso.find_first_not_of (legalASCIICurrencyCharacters) == std::string::npos))
(iso.find_first_not_of (allowed_characters) == std::string::npos))
{
return iso;
}
}
uint160 simple;
simple.copyFrom(currency);
return to_string(simple);
return strHex (currency.begin (), currency.size ());
}
bool to_currency(Currency& currency, std::string const& code)