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:
Ed Hennis
2025-11-06 20:08:11 -05:00
parent 74e331f3e9
commit fdb659dc72
5 changed files with 13 additions and 9 deletions

View File

@@ -482,6 +482,8 @@ public:
value_type
operator*() const;
/// Do not use operator->() unless the field is required, or you've checked
/// that it's set.
T const*
operator->() const;
@@ -739,6 +741,8 @@ STObject::Proxy<T>::operator*() const -> value_type
return this->value();
}
/// Do not use operator->() unless the field is required, or you've checked that
/// it's set.
template <class T>
T const*
STObject::Proxy<T>::operator->() const

View File

@@ -175,7 +175,7 @@ LoanManage::defaultLoan(
// 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
// scale.
auto const vaultScale = vaultTotalProxy->value().exponent();
auto const vaultScale = vaultTotalProxy.value().exponent();
if (vaultTotalProxy < vaultDefaultAmount)
{
@@ -197,13 +197,12 @@ LoanManage::defaultLoan(
auto const difference = vaultAvailableProxy - vaultTotalProxy;
JLOG(j.debug())
<< "Vault assets available: " << *vaultAvailableProxy << "("
<< vaultAvailableProxy->value().exponent()
<< vaultAvailableProxy.value().exponent()
<< "), Total: " << *vaultTotalProxy << "("
<< vaultTotalProxy->value().exponent()
<< vaultTotalProxy.value().exponent()
<< "), Difference: " << difference << "("
<< difference.exponent() << ")";
if (vaultAvailableProxy->value().exponent() -
difference.exponent() >
if (vaultAvailableProxy.value().exponent() - difference.exponent() >
13)
{
// If the difference is dust, bring the total up to match

View File

@@ -351,7 +351,7 @@ LoanPay::doApply()
// 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.
auto const vaultScale = assetsTotalProxy->value().exponent();
auto const vaultScale = assetsTotalProxy.value().exponent();
auto const totalPaidToVaultRaw =
paymentParts->principalPaid + paymentParts->interestPaid;

View File

@@ -420,7 +420,7 @@ LoanSet::doApply()
auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable);
auto vaultTotalProxy = vaultSle->at(sfAssetsTotal);
auto const vaultScale = vaultTotalProxy->value().exponent();
auto const vaultScale = vaultTotalProxy.value().exponent();
if (vaultAvailableProxy < principalRequested)
{
JLOG(j_.warn())
@@ -513,7 +513,7 @@ LoanSet::doApply()
auto const ownerCount = borrowerSle->at(sfOwnerCount);
auto const balance = account_ == borrower
? mPriorBalance
: borrowerSle->at(sfBalance)->xrp();
: borrowerSle->at(sfBalance).value().xrp();
if (balance < view.fees().accountReserve(ownerCount))
return tecINSUFFICIENT_RESERVE;
}

View File

@@ -273,7 +273,8 @@ VaultDeposit::doApply()
}
assetsTotalProxy += assetsDeposited;
assetsAvailableProxy += assetsDeposited;
if (!assetsTotalProxy->valid() || !assetsAvailableProxy->valid())
if (!assetsTotalProxy.value().valid() ||
!assetsAvailableProxy.value().valid())
return tecLIMIT_EXCEEDED;
view().update(vault);