From 59c779fc01d1d506285a3c1510d0741aeff321db Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Mon, 27 Jul 2026 14:50:08 +0200 Subject: [PATCH] refactor: Use static_cast instead of switch in getVaultVersion Address PR review comment: VaultVersion's enumerators already have explicit values, so static_cast(leVersion) avoids repeating them as switch-case magic numbers. Out-of-range values still hit the UNREACHABLE guard. --- src/libxrpl/ledger/helpers/VaultHelpers.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/libxrpl/ledger/helpers/VaultHelpers.cpp b/src/libxrpl/ledger/helpers/VaultHelpers.cpp index 1ac4abdca3..78f64d2077 100644 --- a/src/libxrpl/ledger/helpers/VaultHelpers.cpp +++ b/src/libxrpl/ledger/helpers/VaultHelpers.cpp @@ -14,6 +14,7 @@ #include #include +#include namespace xrpl { @@ -145,18 +146,15 @@ getVaultVersion(SLE::const_ref vault) if (!vault->isFieldPresent(sfLEVersion)) return VaultVersion::Legacy; - switch (vault->at(sfLEVersion)) + auto const version = vault->at(sfLEVersion); + if (version > std::to_underlying(VaultVersion::CashBasis)) { - case 0: - return VaultVersion::Legacy; - case 1: - return VaultVersion::CashBasis; - default: - // LCOV_EXCL_START - UNREACHABLE("xrpl::getVaultVersion : invalid vault version"); - return VaultVersion::Legacy; - // LCOV_EXCL_STOP + // LCOV_EXCL_START + UNREACHABLE("xrpl::getVaultVersion : invalid vault version"); + return VaultVersion::Legacy; + // LCOV_EXCL_STOP } + return static_cast(version); } } // namespace xrpl