Fix underflow issue for XRP:

In some cases multiplying or dividing STAmounts gave incorrect results.

This happens when:

1) The result should be rounded up
2) The STAmount represents a native value (XRP)
3) The rounded up value was less than one drop

In this case, the result was zero, instead of one drop. This could
cause funded offers to be removed as unfunded.
This commit is contained in:
seelabs
2016-02-25 10:07:32 -05:00
parent 3605bf1f60
commit d8ee487c19
4 changed files with 148 additions and 9 deletions

View File

@@ -402,6 +402,7 @@ inline bool isXRP(STAmount const& amount)
}
extern LocalValue<bool> stAmountCalcSwitchover;
extern LocalValue<bool> stAmountCalcSwitchover2;
/** RAII class to set and restore the STAmount calc switchover.*/
class STAmountSO
@@ -409,20 +410,27 @@ class STAmountSO
public:
explicit STAmountSO(NetClock::time_point const closeTime)
: saved_(*stAmountCalcSwitchover)
, saved2_(*stAmountCalcSwitchover2)
{
*stAmountCalcSwitchover = closeTime > soTime;
*stAmountCalcSwitchover2 = closeTime > soTime2;
}
~STAmountSO()
{
*stAmountCalcSwitchover = saved_;
*stAmountCalcSwitchover2 = saved2_;
}
// Mon Dec 28, 2015 10:00:00am PST
static NetClock::time_point const soTime;
// Mon Mar 28, 2015 10:00:00am PST
static NetClock::time_point const soTime2;
private:
bool saved_;
bool saved2_;
};
} // ripple