mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
fix: Use ".value()" instead of "->" when with STObject::Proxy objects
- Turns out that "Proxy::operator->" is not a safe substitute for "Proxy::value()." if the field is not required. The implementation is different such that "operator->" will return a null ptr if the field is not present. This includes default fields with a value of zero!
This commit is contained in:
@@ -482,6 +482,8 @@ public:
|
|||||||
value_type
|
value_type
|
||||||
operator*() const;
|
operator*() const;
|
||||||
|
|
||||||
|
/// Do not use operator->() unless the field is required, or you've checked
|
||||||
|
/// that it's set.
|
||||||
T const*
|
T const*
|
||||||
operator->() const;
|
operator->() const;
|
||||||
|
|
||||||
@@ -739,6 +741,8 @@ STObject::Proxy<T>::operator*() const -> value_type
|
|||||||
return this->value();
|
return this->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Do not use operator->() unless the field is required, or you've checked that
|
||||||
|
/// it's set.
|
||||||
template <class T>
|
template <class T>
|
||||||
T const*
|
T const*
|
||||||
STObject::Proxy<T>::operator->() const
|
STObject::Proxy<T>::operator->() const
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ LoanManage::defaultLoan(
|
|||||||
// The vault may be at a different scale than the loan. Reduce rounding
|
// The vault may be at a different scale than the loan. Reduce rounding
|
||||||
// errors during the accounting by rounding some of the values to that
|
// errors during the accounting by rounding some of the values to that
|
||||||
// scale.
|
// scale.
|
||||||
auto const vaultScale = vaultTotalProxy->value().exponent();
|
auto const vaultScale = vaultTotalProxy.value().exponent();
|
||||||
|
|
||||||
if (vaultTotalProxy < vaultDefaultAmount)
|
if (vaultTotalProxy < vaultDefaultAmount)
|
||||||
{
|
{
|
||||||
@@ -197,13 +197,12 @@ LoanManage::defaultLoan(
|
|||||||
auto const difference = vaultAvailableProxy - vaultTotalProxy;
|
auto const difference = vaultAvailableProxy - vaultTotalProxy;
|
||||||
JLOG(j.debug())
|
JLOG(j.debug())
|
||||||
<< "Vault assets available: " << *vaultAvailableProxy << "("
|
<< "Vault assets available: " << *vaultAvailableProxy << "("
|
||||||
<< vaultAvailableProxy->value().exponent()
|
<< vaultAvailableProxy.value().exponent()
|
||||||
<< "), Total: " << *vaultTotalProxy << "("
|
<< "), Total: " << *vaultTotalProxy << "("
|
||||||
<< vaultTotalProxy->value().exponent()
|
<< vaultTotalProxy.value().exponent()
|
||||||
<< "), Difference: " << difference << "("
|
<< "), Difference: " << difference << "("
|
||||||
<< difference.exponent() << ")";
|
<< difference.exponent() << ")";
|
||||||
if (vaultAvailableProxy->value().exponent() -
|
if (vaultAvailableProxy.value().exponent() - difference.exponent() >
|
||||||
difference.exponent() >
|
|
||||||
13)
|
13)
|
||||||
{
|
{
|
||||||
// If the difference is dust, bring the total up to match
|
// If the difference is dust, bring the total up to match
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ LoanPay::doApply()
|
|||||||
|
|
||||||
// The vault may be at a different scale than the loan. Reduce rounding
|
// The vault may be at a different scale than the loan. Reduce rounding
|
||||||
// errors during the payment by rounding some of the values to that scale.
|
// errors during the payment by rounding some of the values to that scale.
|
||||||
auto const vaultScale = assetsTotalProxy->value().exponent();
|
auto const vaultScale = assetsTotalProxy.value().exponent();
|
||||||
|
|
||||||
auto const totalPaidToVaultRaw =
|
auto const totalPaidToVaultRaw =
|
||||||
paymentParts->principalPaid + paymentParts->interestPaid;
|
paymentParts->principalPaid + paymentParts->interestPaid;
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ LoanSet::doApply()
|
|||||||
|
|
||||||
auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable);
|
auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable);
|
||||||
auto vaultTotalProxy = vaultSle->at(sfAssetsTotal);
|
auto vaultTotalProxy = vaultSle->at(sfAssetsTotal);
|
||||||
auto const vaultScale = vaultTotalProxy->value().exponent();
|
auto const vaultScale = vaultTotalProxy.value().exponent();
|
||||||
if (vaultAvailableProxy < principalRequested)
|
if (vaultAvailableProxy < principalRequested)
|
||||||
{
|
{
|
||||||
JLOG(j_.warn())
|
JLOG(j_.warn())
|
||||||
@@ -513,7 +513,7 @@ LoanSet::doApply()
|
|||||||
auto const ownerCount = borrowerSle->at(sfOwnerCount);
|
auto const ownerCount = borrowerSle->at(sfOwnerCount);
|
||||||
auto const balance = account_ == borrower
|
auto const balance = account_ == borrower
|
||||||
? mPriorBalance
|
? mPriorBalance
|
||||||
: borrowerSle->at(sfBalance)->xrp();
|
: borrowerSle->at(sfBalance).value().xrp();
|
||||||
if (balance < view.fees().accountReserve(ownerCount))
|
if (balance < view.fees().accountReserve(ownerCount))
|
||||||
return tecINSUFFICIENT_RESERVE;
|
return tecINSUFFICIENT_RESERVE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,7 +273,8 @@ VaultDeposit::doApply()
|
|||||||
}
|
}
|
||||||
assetsTotalProxy += assetsDeposited;
|
assetsTotalProxy += assetsDeposited;
|
||||||
assetsAvailableProxy += assetsDeposited;
|
assetsAvailableProxy += assetsDeposited;
|
||||||
if (!assetsTotalProxy->valid() || !assetsAvailableProxy->valid())
|
if (!assetsTotalProxy.value().valid() ||
|
||||||
|
!assetsAvailableProxy.value().valid())
|
||||||
return tecLIMIT_EXCEEDED;
|
return tecLIMIT_EXCEEDED;
|
||||||
view().update(vault);
|
view().update(vault);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user