From 74e331f3e933747eeffd06f74d4861921cf0a65c Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 6 Nov 2025 19:36:40 -0500 Subject: [PATCH] Handle zero rate in `computePaymentFactor` --- src/xrpld/app/misc/detail/LendingHelpers.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xrpld/app/misc/detail/LendingHelpers.cpp b/src/xrpld/app/misc/detail/LendingHelpers.cpp index f8ed477b9b..ad0e98b07e 100644 --- a/src/xrpld/app/misc/detail/LendingHelpers.cpp +++ b/src/xrpld/app/misc/detail/LendingHelpers.cpp @@ -73,6 +73,12 @@ computePaymentFactor( Number const& periodicRate, std::uint32_t paymentsRemaining) { + // periodicRate should never be zero in this function, but if it is, + // then 1/paymentRemaining is the most accurate factor that avoids + // divide by 0. + if (periodicRate == beast::zero) + return Number{1} / paymentsRemaining; + /* * This formula is from the XLS-66 spec, section 3.2.4.1.1 (Regular * Payment), though "raisedRate" is computed only once and used twice.