mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
refactor: change the return type of mulDiv to std::optional (#4243)
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type.
- This is an error-prone interface as it is easy to ignore when
overflow occurs.
- Using a return type of `std::optional` should decrease the likelihood
of ignoring overflow.
- It also allows for the use of optional::value_or() as a way to
explicitly recover from overflow.
- Include limits.h header file preprocessing directive in order to
satisfy gcc's numeric_limits incomplete_type requirement.
Fix #3495
---------
Co-authored-by: John Freeman <jfreeman08@gmail.com>
This commit is contained in:
committed by
GitHub
parent
77dc63b549
commit
c6fee28b92
@@ -20,7 +20,6 @@
|
||||
#include <ripple/app/ledger/OpenLedger.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/app/misc/TxQ.h>
|
||||
#include <ripple/basics/mulDiv.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/Feature.h>
|
||||
#include <ripple/rpc/Context.h>
|
||||
|
||||
@@ -738,9 +738,9 @@ checkFee(
|
||||
auto const limit = [&]() {
|
||||
// Scale fee units to drops:
|
||||
auto const result = mulDiv(feeDefault, mult, div);
|
||||
if (!result.first)
|
||||
if (!result)
|
||||
Throw<std::overflow_error>("mulDiv");
|
||||
return result.second;
|
||||
return *result;
|
||||
}();
|
||||
|
||||
if (fee > limit)
|
||||
|
||||
Reference in New Issue
Block a user