mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add safe_cast (RIPD-1702):
This change ensures that no overflow can occur when casting between enums and integral types.
This commit is contained in:
committed by
Nik Bougalis
parent
494724578a
commit
148bbf4e8f
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/safe_cast.h>
|
||||
#include <ripple/protocol/LedgerFormats.h>
|
||||
#include <ripple/protocol/STInteger.h>
|
||||
#include <ripple/protocol/TxFormats.h>
|
||||
@@ -98,7 +99,7 @@ STUInt16::getText () const
|
||||
if (getFName () == sfLedgerEntryType)
|
||||
{
|
||||
auto item = LedgerFormats::getInstance ().findByType (
|
||||
static_cast <LedgerEntryType> (value_));
|
||||
safe_cast<LedgerEntryType> (value_));
|
||||
|
||||
if (item != nullptr)
|
||||
return item->getName ();
|
||||
@@ -107,7 +108,7 @@ STUInt16::getText () const
|
||||
if (getFName () == sfTransactionType)
|
||||
{
|
||||
auto item =TxFormats::getInstance().findByType (
|
||||
static_cast <TxType> (value_));
|
||||
safe_cast<TxType> (value_));
|
||||
|
||||
if (item != nullptr)
|
||||
return item->getName ();
|
||||
@@ -123,7 +124,7 @@ STUInt16::getJson (int) const
|
||||
if (getFName () == sfLedgerEntryType)
|
||||
{
|
||||
auto item = LedgerFormats::getInstance ().findByType (
|
||||
static_cast <LedgerEntryType> (value_));
|
||||
safe_cast<LedgerEntryType> (value_));
|
||||
|
||||
if (item != nullptr)
|
||||
return item->getName ();
|
||||
@@ -132,7 +133,7 @@ STUInt16::getJson (int) const
|
||||
if (getFName () == sfTransactionType)
|
||||
{
|
||||
auto item = TxFormats::getInstance().findByType (
|
||||
static_cast <TxType> (value_));
|
||||
safe_cast<TxType> (value_));
|
||||
|
||||
if (item != nullptr)
|
||||
return item->getName ();
|
||||
|
||||
Reference in New Issue
Block a user